1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Chelsio Communications.
6 #include <ethdev_driver.h>
13 * t4vf_wait_dev_ready - wait till to reads of registers work
15 * Wait for the device to become ready (signified by our "who am I" register
16 * returning a value other than all 1's). Return an error if it doesn't
19 static int t4vf_wait_dev_ready(struct adapter *adapter)
21 const u32 whoami = T4VF_PL_BASE_ADDR + A_PL_VF_WHOAMI;
22 const u32 notready1 = 0xffffffff;
23 const u32 notready2 = 0xeeeeeeee;
26 val = t4_read_reg(adapter, whoami);
27 if (val != notready1 && val != notready2)
31 val = t4_read_reg(adapter, whoami);
32 if (val != notready1 && val != notready2)
35 dev_err(adapter, "Device didn't become ready for access, whoami = %#x\n",
41 * Get the reply to a mailbox command and store it in @rpl in big-endian order.
43 static void get_mbox_rpl(struct adapter *adap, __be64 *rpl, int nflit,
46 for ( ; nflit; nflit--, mbox_addr += 8)
47 *rpl++ = cpu_to_be64(t4_read_reg64(adap, mbox_addr));
51 * t4vf_wr_mbox_core - send a command to FW through the mailbox
52 * @adapter: the adapter
53 * @cmd: the command to write
54 * @size: command length in bytes
55 * @rpl: where to optionally store the reply
56 * @sleep_ok: if true we may sleep while awaiting command completion
58 * Sends the given command to FW through the mailbox and waits for the
59 * FW to execute the command. If @rpl is not %NULL it is used to store
60 * the FW's reply to the command. The command and its optional reply
61 * are of the same length. FW can take up to 500 ms to respond.
62 * @sleep_ok determines whether we may sleep while awaiting the response.
63 * If sleeping is allowed we use progressive backoff otherwise we spin.
65 * The return value is 0 on success or a negative errno on failure. A
66 * failure can happen either because we are not able to execute the
67 * command or FW executes it but signals an error. In the latter case
68 * the return value is the error code indicated by FW (negated).
70 int t4vf_wr_mbox_core(struct adapter *adapter,
71 const void __attribute__((__may_alias__)) *cmd,
72 int size, void *rpl, bool sleep_ok)
75 * We delay in small increments at first in an effort to maintain
76 * responsiveness for simple, fast executing commands but then back
77 * off to larger delays to a maximum retry delay.
79 static const int delay[] = {
80 1, 1, 3, 5, 10, 10, 20, 50, 100
84 u32 mbox_ctl = T4VF_CIM_BASE_ADDR + A_CIM_VF_EXT_MAILBOX_CTRL;
85 __be64 cmd_rpl[MBOX_LEN / 8];
86 struct mbox_entry *entry;
87 unsigned int delay_idx;
93 /* In T6, mailbox size is changed to 128 bytes to avoid
94 * invalidating the entire prefetch buffer.
96 if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
97 mbox_data = T4VF_MBDATA_BASE_ADDR;
99 mbox_data = T6VF_MBDATA_BASE_ADDR;
102 * Commands must be multiples of 16 bytes in length and may not be
103 * larger than the size of the Mailbox Data register array.
105 if ((size % 16) != 0 ||
106 size > NUM_CIM_VF_MAILBOX_DATA_INSTANCES * 4)
109 entry = t4_os_alloc(sizeof(*entry));
114 * Queue ourselves onto the mailbox access list. When our entry is at
115 * the front of the list, we have rights to access the mailbox. So we
116 * wait [for a while] till we're at the front [or bail out with an
119 t4_os_atomic_add_tail(entry, &adapter->mbox_list, &adapter->mbox_lock);
124 for (i = 0; ; i += ms) {
126 * If we've waited too long, return a busy indication. This
127 * really ought to be based on our initial position in the
128 * mailbox access list but this is a start. We very rarely
129 * contend on access to the mailbox ...
131 if (i > (2 * FW_CMD_MAX_TIMEOUT)) {
132 t4_os_atomic_list_del(entry, &adapter->mbox_list,
133 &adapter->mbox_lock);
139 * If we're at the head, break out and start the mailbox
142 if (t4_os_list_first_entry(&adapter->mbox_list) == entry)
146 * Delay for a bit before checking again ...
149 ms = delay[delay_idx]; /* last element may repeat */
150 if (delay_idx < ARRAY_SIZE(delay) - 1)
159 * Loop trying to get ownership of the mailbox. Return an error
160 * if we can't gain ownership.
162 v = G_MBOWNER(t4_read_reg(adapter, mbox_ctl));
163 for (i = 0; v == X_MBOWNER_NONE && i < 3; i++)
164 v = G_MBOWNER(t4_read_reg(adapter, mbox_ctl));
166 if (v != X_MBOWNER_PL) {
167 t4_os_atomic_list_del(entry, &adapter->mbox_list,
168 &adapter->mbox_lock);
169 ret = (v == X_MBOWNER_FW) ? -EBUSY : -ETIMEDOUT;
174 * Write the command array into the Mailbox Data register array and
175 * transfer ownership of the mailbox to the firmware.
177 for (i = 0, p = cmd; i < size; i += 8)
178 t4_write_reg64(adapter, mbox_data + i, be64_to_cpu(*p++));
180 t4_read_reg(adapter, mbox_data); /* flush write */
181 t4_write_reg(adapter, mbox_ctl,
182 F_MBMSGVALID | V_MBOWNER(X_MBOWNER_FW));
183 t4_read_reg(adapter, mbox_ctl); /* flush write */
188 * Spin waiting for firmware to acknowledge processing our command.
190 for (i = 0; i < FW_CMD_MAX_TIMEOUT; i++) {
192 ms = delay[delay_idx]; /* last element may repeat */
193 if (delay_idx < ARRAY_SIZE(delay) - 1)
201 * If we're the owner, see if this is the reply we wanted.
203 v = t4_read_reg(adapter, mbox_ctl);
204 if (G_MBOWNER(v) == X_MBOWNER_PL) {
206 * If the Message Valid bit isn't on, revoke ownership
207 * of the mailbox and continue waiting for our reply.
209 if ((v & F_MBMSGVALID) == 0) {
210 t4_write_reg(adapter, mbox_ctl,
211 V_MBOWNER(X_MBOWNER_NONE));
216 * We now have our reply. Extract the command return
217 * value, copy the reply back to our caller's buffer
218 * (if specified) and revoke ownership of the mailbox.
219 * We return the (negated) firmware command return
220 * code (this depends on FW_SUCCESS == 0). (Again we
221 * avoid clogging the log with FW_VI_STATS_CMD
226 * Retrieve the command reply and release the mailbox.
228 get_mbox_rpl(adapter, cmd_rpl, size / 8, mbox_data);
229 t4_write_reg(adapter, mbox_ctl,
230 V_MBOWNER(X_MBOWNER_NONE));
231 t4_os_atomic_list_del(entry, &adapter->mbox_list,
232 &adapter->mbox_lock);
234 /* return value in high-order host-endian word */
235 v = be64_to_cpu(cmd_rpl[0]);
238 /* request bit in high-order BE word */
239 WARN_ON((be32_to_cpu(*(const u32 *)cmd)
240 & F_FW_CMD_REQUEST) == 0);
241 memcpy(rpl, cmd_rpl, size);
243 ret = -((int)G_FW_CMD_RETVAL(v));
249 * We timed out. Return the error ...
251 dev_err(adapter, "command %#x timed out\n",
253 dev_err(adapter, " Control = %#x\n", t4_read_reg(adapter, mbox_ctl));
254 t4_os_atomic_list_del(entry, &adapter->mbox_list, &adapter->mbox_lock);
263 * t4vf_fw_reset - issue a reset to FW
264 * @adapter: the adapter
266 * Issues a reset command to FW. For a Physical Function this would
267 * result in the Firmware resetting all of its state. For a Virtual
268 * Function this just resets the state associated with the VF.
270 int t4vf_fw_reset(struct adapter *adapter)
272 struct fw_reset_cmd cmd;
274 memset(&cmd, 0, sizeof(cmd));
275 cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_RESET_CMD) |
277 cmd.retval_len16 = cpu_to_be32(V_FW_CMD_LEN16(FW_LEN16(cmd)));
278 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
282 * t4vf_prep_adapter - prepare SW and HW for operation
283 * @adapter: the adapter
285 * Initialize adapter SW state for the various HW modules, set initial
286 * values for some adapter tunables, take PHYs out of reset, and
287 * initialize the MDIO interface.
289 int t4vf_prep_adapter(struct adapter *adapter)
294 ret = t4vf_wait_dev_ready(adapter);
299 * Default port and clock for debugging in case we can't reach
302 adapter->params.nports = 1;
303 adapter->params.vfres.pmask = 1;
304 adapter->params.vpd.cclk = 50000;
306 pl_vf_rev = G_REV(t4_read_reg(adapter, A_PL_VF_REV));
307 adapter->params.pci.device_id = adapter->pdev->id.device_id;
308 adapter->params.pci.vendor_id = adapter->pdev->id.vendor_id;
311 * WE DON'T NEED adapter->params.chip CODE ONCE PL_REV CONTAINS
312 * ADAPTER (VERSION << 4 | REVISION)
314 ver = CHELSIO_PCI_ID_VER(adapter->params.pci.device_id);
315 adapter->params.chip = 0;
318 adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T5,
320 adapter->params.arch.sge_fl_db = F_DBPRIO | F_DBTYPE;
321 adapter->params.arch.mps_tcam_size =
322 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
325 adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T6,
327 adapter->params.arch.sge_fl_db = 0;
328 adapter->params.arch.mps_tcam_size =
329 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
332 dev_err(adapter, "%s: Device %d is not supported\n",
333 __func__, adapter->params.pci.device_id);
340 * t4vf_query_params - query FW or device parameters
341 * @adapter: the adapter
342 * @nparams: the number of parameters
343 * @params: the parameter names
344 * @vals: the parameter values
346 * Reads the values of firmware or device parameters. Up to 7 parameters
347 * can be queried at once.
349 int t4vf_query_params(struct adapter *adapter, unsigned int nparams,
350 const u32 *params, u32 *vals)
352 struct fw_params_cmd cmd, rpl;
353 struct fw_params_param *p;
361 memset(&cmd, 0, sizeof(cmd));
362 cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_PARAMS_CMD) |
365 len16 = DIV_ROUND_UP(offsetof(struct fw_params_cmd,
366 param[nparams]), 16);
367 cmd.retval_len16 = cpu_to_be32(V_FW_CMD_LEN16(len16));
368 for (i = 0, p = &cmd.param[0]; i < nparams; i++, p++)
369 p->mnem = cpu_to_be32(*params++);
370 ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
372 for (i = 0, p = &rpl.param[0]; i < nparams; i++, p++)
373 *vals++ = be32_to_cpu(p->val);
378 * t4vf_get_vpd_params - retrieve device VPD paremeters
379 * @adapter: the adapter
381 * Retrives various device Vital Product Data parameters. The parameters
382 * are stored in @adapter->params.vpd.
384 int t4vf_get_vpd_params(struct adapter *adapter)
386 struct vpd_params *vpd_params = &adapter->params.vpd;
387 u32 params[7], vals[7];
390 params[0] = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
391 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_CCLK));
392 v = t4vf_query_params(adapter, 1, params, vals);
395 vpd_params->cclk = vals[0];
396 dev_debug(adapter, "%s: vpd_params->cclk = %u\n",
397 __func__, vpd_params->cclk);
402 * t4vf_get_dev_params - retrieve device paremeters
403 * @adapter: the adapter
405 * Retrives fw and tp version.
407 int t4vf_get_dev_params(struct adapter *adapter)
409 u32 params[7], vals[7];
412 params[0] = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
413 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FWREV));
414 params[1] = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
415 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_TPREV));
416 v = t4vf_query_params(adapter, 2, params, vals);
419 adapter->params.fw_vers = vals[0];
420 adapter->params.tp_vers = vals[1];
422 dev_info(adapter, "Firmware version: %u.%u.%u.%u\n",
423 G_FW_HDR_FW_VER_MAJOR(adapter->params.fw_vers),
424 G_FW_HDR_FW_VER_MINOR(adapter->params.fw_vers),
425 G_FW_HDR_FW_VER_MICRO(adapter->params.fw_vers),
426 G_FW_HDR_FW_VER_BUILD(adapter->params.fw_vers));
428 dev_info(adapter, "TP Microcode version: %u.%u.%u.%u\n",
429 G_FW_HDR_FW_VER_MAJOR(adapter->params.tp_vers),
430 G_FW_HDR_FW_VER_MINOR(adapter->params.tp_vers),
431 G_FW_HDR_FW_VER_MICRO(adapter->params.tp_vers),
432 G_FW_HDR_FW_VER_BUILD(adapter->params.tp_vers));
437 * t4vf_set_params - sets FW or device parameters
438 * @adapter: the adapter
439 * @nparams: the number of parameters
440 * @params: the parameter names
441 * @vals: the parameter values
443 * Sets the values of firmware or device parameters. Up to 7 parameters
444 * can be specified at once.
446 int t4vf_set_params(struct adapter *adapter, unsigned int nparams,
447 const u32 *params, const u32 *vals)
449 struct fw_params_param *p;
450 struct fw_params_cmd cmd;
457 memset(&cmd, 0, sizeof(cmd));
458 cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_PARAMS_CMD) |
461 len16 = DIV_ROUND_UP(offsetof(struct fw_params_cmd,
462 param[nparams]), 16);
463 cmd.retval_len16 = cpu_to_be32(V_FW_CMD_LEN16(len16));
464 for (i = 0, p = &cmd.param[0]; i < nparams; i++, p++) {
465 p->mnem = cpu_to_be32(*params++);
466 p->val = cpu_to_be32(*vals++);
468 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
471 unsigned int t4vf_get_pf_from_vf(struct adapter *adapter)
475 whoami = t4_read_reg(adapter, T4VF_PL_BASE_ADDR + A_PL_VF_WHOAMI);
476 return (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5 ?
477 G_SOURCEPF(whoami) : G_T6_SOURCEPF(whoami));
481 * t4vf_get_rss_glb_config - retrieve adapter RSS Global Configuration
482 * @adapter: the adapter
484 * Retrieves global RSS mode and parameters with which we have to live
485 * and stores them in the @adapter's RSS parameters.
487 int t4vf_get_rss_glb_config(struct adapter *adapter)
489 struct rss_params *rss = &adapter->params.rss;
490 struct fw_rss_glb_config_cmd cmd, rpl;
494 * Execute an RSS Global Configuration read command to retrieve
495 * our RSS configuration.
497 memset(&cmd, 0, sizeof(cmd));
498 cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_RSS_GLB_CONFIG_CMD) |
501 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
502 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
507 * Translate the big-endian RSS Global Configuration into our
508 * cpu-endian format based on the RSS mode. We also do first level
509 * filtering at this point to weed out modes which don't support
512 rss->mode = G_FW_RSS_GLB_CONFIG_CMD_MODE
513 (be32_to_cpu(rpl.u.manual.mode_pkd));
515 case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
516 u32 word = be32_to_cpu
517 (rpl.u.basicvirtual.synmapen_to_hashtoeplitz);
519 rss->u.basicvirtual.synmapen =
520 ((word & F_FW_RSS_GLB_CONFIG_CMD_SYNMAPEN) != 0);
521 rss->u.basicvirtual.syn4tupenipv6 =
522 ((word & F_FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV6) != 0);
523 rss->u.basicvirtual.syn2tupenipv6 =
524 ((word & F_FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV6) != 0);
525 rss->u.basicvirtual.syn4tupenipv4 =
526 ((word & F_FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV4) != 0);
527 rss->u.basicvirtual.syn2tupenipv4 =
528 ((word & F_FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV4) != 0);
529 rss->u.basicvirtual.ofdmapen =
530 ((word & F_FW_RSS_GLB_CONFIG_CMD_OFDMAPEN) != 0);
531 rss->u.basicvirtual.tnlmapen =
532 ((word & F_FW_RSS_GLB_CONFIG_CMD_TNLMAPEN) != 0);
533 rss->u.basicvirtual.tnlalllookup =
534 ((word & F_FW_RSS_GLB_CONFIG_CMD_TNLALLLKP) != 0);
535 rss->u.basicvirtual.hashtoeplitz =
536 ((word & F_FW_RSS_GLB_CONFIG_CMD_HASHTOEPLITZ) != 0);
538 /* we need at least Tunnel Map Enable to be set */
539 if (!rss->u.basicvirtual.tnlmapen)
545 /* all unknown/unsupported RSS modes result in an error */
552 * t4vf_get_vfres - retrieve VF resource limits
553 * @adapter: the adapter
555 * Retrieves configured resource limits and capabilities for a virtual
556 * function. The results are stored in @adapter->vfres.
558 int t4vf_get_vfres(struct adapter *adapter)
560 struct vf_resources *vfres = &adapter->params.vfres;
561 struct fw_pfvf_cmd cmd, rpl;
566 * Execute PFVF Read command to get VF resource limits; bail out early
567 * with error on command failure.
569 memset(&cmd, 0, sizeof(cmd));
570 cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_PFVF_CMD) |
573 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
574 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
579 * Extract VF resource limits and return success.
581 word = be32_to_cpu(rpl.niqflint_niq);
582 vfres->niqflint = G_FW_PFVF_CMD_NIQFLINT(word);
583 vfres->niq = G_FW_PFVF_CMD_NIQ(word);
585 word = be32_to_cpu(rpl.type_to_neq);
586 vfres->neq = G_FW_PFVF_CMD_NEQ(word);
587 vfres->pmask = G_FW_PFVF_CMD_PMASK(word);
589 word = be32_to_cpu(rpl.tc_to_nexactf);
590 vfres->tc = G_FW_PFVF_CMD_TC(word);
591 vfres->nvi = G_FW_PFVF_CMD_NVI(word);
592 vfres->nexactf = G_FW_PFVF_CMD_NEXACTF(word);
594 word = be32_to_cpu(rpl.r_caps_to_nethctrl);
595 vfres->r_caps = G_FW_PFVF_CMD_R_CAPS(word);
596 vfres->wx_caps = G_FW_PFVF_CMD_WX_CAPS(word);
597 vfres->nethctrl = G_FW_PFVF_CMD_NETHCTRL(word);
602 * t4vf_get_port_stats_fw - collect "port" statistics via Firmware
603 * @adapter: the adapter
604 * @pidx: the port index
605 * @s: the stats structure to fill
607 * Collect statistics for the "port"'s Virtual Interface via Firmware
610 static int t4vf_get_port_stats_fw(struct adapter *adapter, int pidx,
611 struct port_stats *p)
613 struct port_info *pi = adap2pinfo(adapter, pidx);
614 unsigned int rem = VI_VF_NUM_STATS;
615 struct fw_vi_stats_vf fwstats;
616 __be64 *fwsp = (__be64 *)&fwstats;
619 * Grab the Virtual Interface statistics a chunk at a time via mailbox
620 * commands. We could use a Work Request and get all of them at once
621 * but that's an asynchronous interface which is awkward to use.
624 unsigned int ix = VI_VF_NUM_STATS - rem;
625 unsigned int nstats = min(6U, rem);
626 struct fw_vi_stats_cmd cmd, rpl;
627 size_t len = (offsetof(struct fw_vi_stats_cmd, u) +
628 sizeof(struct fw_vi_stats_ctl));
629 size_t len16 = DIV_ROUND_UP(len, 16);
632 memset(&cmd, 0, sizeof(cmd));
633 cmd.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_STATS_CMD) |
634 V_FW_VI_STATS_CMD_VIID(pi->viid) |
637 cmd.retval_len16 = cpu_to_be32(V_FW_CMD_LEN16(len16));
638 cmd.u.ctl.nstats_ix =
639 cpu_to_be16(V_FW_VI_STATS_CMD_IX(ix) |
640 V_FW_VI_STATS_CMD_NSTATS(nstats));
641 ret = t4vf_wr_mbox_ns(adapter, &cmd, len, &rpl);
642 if (ret != FW_SUCCESS)
645 memcpy(fwsp, &rpl.u.ctl.stat0, sizeof(__be64) * nstats);
652 * Translate firmware statistics into host native statistics.
654 p->tx_octets = be64_to_cpu(fwstats.tx_bcast_bytes) +
655 be64_to_cpu(fwstats.tx_mcast_bytes) +
656 be64_to_cpu(fwstats.tx_ucast_bytes);
657 p->tx_bcast_frames = be64_to_cpu(fwstats.tx_bcast_frames);
658 p->tx_mcast_frames = be64_to_cpu(fwstats.tx_mcast_frames);
659 p->tx_ucast_frames = be64_to_cpu(fwstats.tx_ucast_frames);
660 p->tx_drop = be64_to_cpu(fwstats.tx_drop_frames);
662 p->rx_bcast_frames = be64_to_cpu(fwstats.rx_bcast_frames);
663 p->rx_mcast_frames = be64_to_cpu(fwstats.rx_mcast_frames);
664 p->rx_ucast_frames = be64_to_cpu(fwstats.rx_ucast_frames);
665 p->rx_len_err = be64_to_cpu(fwstats.rx_err_frames);
671 * t4vf_get_port_stats - collect "port" statistics
672 * @adapter: the adapter
673 * @pidx: the port index
674 * @s: the stats structure to fill
676 * Collect statistics for the "port"'s Virtual Interface.
678 void t4vf_get_port_stats(struct adapter *adapter, int pidx,
679 struct port_stats *p)
682 * If this is not the first Virtual Interface for our Virtual
683 * Function, we need to use Firmware commands to retrieve its
687 t4vf_get_port_stats_fw(adapter, pidx, p);
690 * But for the first VI, we can grab its statistics via the MPS
691 * register mapped into the VF register space.
693 #define GET_STAT(name) \
694 t4_read_reg64(adapter, \
695 T4VF_MPS_BASE_ADDR + A_MPS_VF_STAT_##name##_L)
696 p->tx_octets = GET_STAT(TX_VF_BCAST_BYTES) +
697 GET_STAT(TX_VF_MCAST_BYTES) +
698 GET_STAT(TX_VF_UCAST_BYTES);
699 p->tx_bcast_frames = GET_STAT(TX_VF_BCAST_FRAMES);
700 p->tx_mcast_frames = GET_STAT(TX_VF_MCAST_FRAMES);
701 p->tx_ucast_frames = GET_STAT(TX_VF_UCAST_FRAMES);
702 p->tx_drop = GET_STAT(TX_VF_DROP_FRAMES);
704 p->rx_bcast_frames = GET_STAT(RX_VF_BCAST_FRAMES);
705 p->rx_mcast_frames = GET_STAT(RX_VF_MCAST_FRAMES);
706 p->rx_ucast_frames = GET_STAT(RX_VF_UCAST_FRAMES);
708 p->rx_len_err = GET_STAT(RX_VF_ERR_FRAMES);
712 static int t4vf_alloc_vi(struct adapter *adapter, int port_id)
714 struct fw_vi_cmd cmd, rpl;
718 * Execute a VI command to allocate Virtual Interface and return its
721 memset(&cmd, 0, sizeof(cmd));
722 cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_VI_CMD) |
726 cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(cmd) |
728 cmd.portid_pkd = V_FW_VI_CMD_PORTID(port_id);
729 v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
732 return G_FW_VI_CMD_VIID(be16_to_cpu(rpl.type_to_viid));
735 int t4vf_port_init(struct adapter *adapter)
737 struct fw_port_cmd port_cmd, port_rpl, rpl;
738 struct fw_vi_cmd vi_cmd, vi_rpl;
739 u32 param, val, pcaps, acaps;
740 enum fw_port_type port_type;
744 param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) |
745 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_PORT_CAPS32));
747 ret = t4vf_set_params(adapter, 1, ¶m, &val);
751 for_each_port(adapter, i) {
752 struct port_info *p = adap2pinfo(adapter, i);
755 ret = t4vf_alloc_vi(adapter, p->port_id);
757 dev_err(&pdev->dev, "cannot allocate VI for port %d:"
758 " err=%d\n", p->port_id, ret);
764 * Execute a VI Read command to get our Virtual Interface
765 * information like MAC address, etc.
767 memset(&vi_cmd, 0, sizeof(vi_cmd));
768 vi_cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_VI_CMD) |
771 vi_cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(vi_cmd));
772 vi_cmd.type_to_viid = cpu_to_be16(V_FW_VI_CMD_VIID(p->viid));
773 ret = t4vf_wr_mbox(adapter, &vi_cmd, sizeof(vi_cmd), &vi_rpl);
774 if (ret != FW_SUCCESS)
777 p->rss_size = G_FW_VI_CMD_RSSSIZE
778 (be16_to_cpu(vi_rpl.norss_rsssize));
779 t4_os_set_hw_addr(adapter, i, vi_rpl.mac);
782 * If we don't have read access to our port information, we're
783 * done now. Else, execute a PORT Read command to get it ...
785 if (!(adapter->params.vfres.r_caps & FW_CMD_CAP_PORT))
788 memset(&port_cmd, 0, sizeof(port_cmd));
789 port_cmd.op_to_portid =
790 cpu_to_be32(V_FW_CMD_OP(FW_PORT_CMD) |
791 F_FW_CMD_REQUEST | F_FW_CMD_READ |
792 V_FW_PORT_CMD_PORTID(p->port_id));
793 val = FW_PORT_ACTION_GET_PORT_INFO32;
794 port_cmd.action_to_len16 =
795 cpu_to_be32(V_FW_PORT_CMD_ACTION(val) |
797 ret = t4vf_wr_mbox(adapter, &port_cmd, sizeof(port_cmd),
799 if (ret != FW_SUCCESS)
803 * Extract the various fields from the Port Information message.
806 lstatus32 = be32_to_cpu(rpl.u.info32.lstatus32_to_cbllen32);
808 port_type = G_FW_PORT_CMD_PORTTYPE32(lstatus32);
809 mdio_addr = (lstatus32 & F_FW_PORT_CMD_MDIOCAP32) ?
810 (int)G_FW_PORT_CMD_MDIOADDR32(lstatus32) : -1;
811 pcaps = be32_to_cpu(port_rpl.u.info32.pcaps32);
812 acaps = be32_to_cpu(port_rpl.u.info32.acaps32);
814 t4_init_link_config(p, pcaps, acaps, mdio_addr, port_type,
815 FW_PORT_MOD_TYPE_NA);