1 From 344af44442388ea7f34cb4c4d88fa1162f8d4ddf Mon Sep 17 00:00:00 2001
2 From: Bogdan Purcareata <bogdan.purcareata@nxp.com>
3 Date: Wed, 12 Apr 2017 12:38:57 +0000
4 Subject: [PATCH] staging: fsl-dpaa2/mac: Add APIs for DPMAC objects
6 Add the command build/parse APIs for operating on DPMAC
7 objects through the DPAA2 Management Complex.
9 Signed-off-by: Bogdan Hamciuc <bogdan.hamciuc@nxp.com>
10 Signed-off-by: Bogdan Purcareata <bogdan.purcareata@nxp.com>
12 drivers/staging/fsl-dpaa2/mac/dpmac-cmd.h | 172 +++++++++
13 drivers/staging/fsl-dpaa2/mac/dpmac.c | 620 ++++++++++++++++++++++++++++++
14 drivers/staging/fsl-dpaa2/mac/dpmac.h | 342 ++++++++++++++++
15 3 files changed, 1134 insertions(+)
16 create mode 100644 drivers/staging/fsl-dpaa2/mac/dpmac-cmd.h
17 create mode 100644 drivers/staging/fsl-dpaa2/mac/dpmac.c
18 create mode 100644 drivers/staging/fsl-dpaa2/mac/dpmac.h
21 +++ b/drivers/staging/fsl-dpaa2/mac/dpmac-cmd.h
23 +/* Copyright 2013-2016 Freescale Semiconductor Inc.
25 + * Redistribution and use in source and binary forms, with or without
26 + * modification, are permitted provided that the following conditions are met:
27 + * * Redistributions of source code must retain the above copyright
28 + * notice, this list of conditions and the following disclaimer.
29 + * * Redistributions in binary form must reproduce the above copyright
30 + * notice, this list of conditions and the following disclaimer in the
31 + * documentation and/or other materials provided with the distribution.
32 + * * Neither the name of the above-listed copyright holders nor the
33 + * names of any contributors may be used to endorse or promote products
34 + * derived from this software without specific prior written permission.
37 + * ALTERNATIVELY, this software may be distributed under the terms of the
38 + * GNU General Public License ("GPL") as published by the Free Software
39 + * Foundation, either version 2 of that License or (at your option) any
42 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52 + * POSSIBILITY OF SUCH DAMAGE.
54 +#ifndef _FSL_DPMAC_CMD_H
55 +#define _FSL_DPMAC_CMD_H
58 +#define DPMAC_VER_MAJOR 4
59 +#define DPMAC_VER_MINOR 2
60 +#define DPMAC_CMD_BASE_VERSION 1
61 +#define DPMAC_CMD_ID_OFFSET 4
63 +#define DPMAC_CMD(id) (((id) << DPMAC_CMD_ID_OFFSET) | DPMAC_CMD_BASE_VERSION)
66 +#define DPMAC_CMDID_CLOSE DPMAC_CMD(0x800)
67 +#define DPMAC_CMDID_OPEN DPMAC_CMD(0x80c)
68 +#define DPMAC_CMDID_CREATE DPMAC_CMD(0x90c)
69 +#define DPMAC_CMDID_DESTROY DPMAC_CMD(0x98c)
70 +#define DPMAC_CMDID_GET_API_VERSION DPMAC_CMD(0xa0c)
72 +#define DPMAC_CMDID_GET_ATTR DPMAC_CMD(0x004)
73 +#define DPMAC_CMDID_RESET DPMAC_CMD(0x005)
75 +#define DPMAC_CMDID_SET_IRQ_ENABLE DPMAC_CMD(0x012)
76 +#define DPMAC_CMDID_GET_IRQ_ENABLE DPMAC_CMD(0x013)
77 +#define DPMAC_CMDID_SET_IRQ_MASK DPMAC_CMD(0x014)
78 +#define DPMAC_CMDID_GET_IRQ_MASK DPMAC_CMD(0x015)
79 +#define DPMAC_CMDID_GET_IRQ_STATUS DPMAC_CMD(0x016)
80 +#define DPMAC_CMDID_CLEAR_IRQ_STATUS DPMAC_CMD(0x017)
82 +#define DPMAC_CMDID_GET_LINK_CFG DPMAC_CMD(0x0c2)
83 +#define DPMAC_CMDID_SET_LINK_STATE DPMAC_CMD(0x0c3)
84 +#define DPMAC_CMDID_GET_COUNTER DPMAC_CMD(0x0c4)
86 +#define DPMAC_CMDID_SET_PORT_MAC_ADDR DPMAC_CMD(0x0c5)
88 +/* Macros for accessing command fields smaller than 1byte */
89 +#define DPMAC_MASK(field) \
90 + GENMASK(DPMAC_##field##_SHIFT + DPMAC_##field##_SIZE - 1, \
91 + DPMAC_##field##_SHIFT)
92 +#define dpmac_set_field(var, field, val) \
93 + ((var) |= (((val) << DPMAC_##field##_SHIFT) & DPMAC_MASK(field)))
94 +#define dpmac_get_field(var, field) \
95 + (((var) & DPMAC_MASK(field)) >> DPMAC_##field##_SHIFT)
97 +struct dpmac_cmd_open {
101 +struct dpmac_cmd_create {
105 +struct dpmac_cmd_destroy {
109 +struct dpmac_cmd_set_irq_enable {
115 +struct dpmac_cmd_get_irq_enable {
120 +struct dpmac_rsp_get_irq_enable {
124 +struct dpmac_cmd_set_irq_mask {
129 +struct dpmac_cmd_get_irq_mask {
134 +struct dpmac_rsp_get_irq_mask {
138 +struct dpmac_cmd_get_irq_status {
143 +struct dpmac_rsp_get_irq_status {
147 +struct dpmac_cmd_clear_irq_status {
152 +struct dpmac_rsp_get_attributes {
159 +struct dpmac_rsp_get_link_cfg {
164 +#define DPMAC_STATE_SIZE 1
165 +#define DPMAC_STATE_SHIFT 0
167 +struct dpmac_cmd_set_link_state {
171 + /* only least significant bit is valid */
175 +struct dpmac_cmd_get_counter {
179 +struct dpmac_rsp_get_counter {
184 +struct dpmac_rsp_get_api_version {
189 +struct dpmac_cmd_set_port_mac_addr {
194 +#endif /* _FSL_DPMAC_CMD_H */
196 +++ b/drivers/staging/fsl-dpaa2/mac/dpmac.c
198 +/* Copyright 2013-2016 Freescale Semiconductor Inc.
200 + * Redistribution and use in source and binary forms, with or without
201 + * modification, are permitted provided that the following conditions are met:
202 + * * Redistributions of source code must retain the above copyright
203 + * notice, this list of conditions and the following disclaimer.
204 + * * Redistributions in binary form must reproduce the above copyright
205 + * notice, this list of conditions and the following disclaimer in the
206 + * documentation and/or other materials provided with the distribution.
207 + * * Neither the name of the above-listed copyright holders nor the
208 + * names of any contributors may be used to endorse or promote products
209 + * derived from this software without specific prior written permission.
212 + * ALTERNATIVELY, this software may be distributed under the terms of the
213 + * GNU General Public License ("GPL") as published by the Free Software
214 + * Foundation, either version 2 of that License or (at your option) any
217 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
218 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
219 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
220 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
221 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
222 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
223 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
224 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
225 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
226 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
227 + * POSSIBILITY OF SUCH DAMAGE.
229 +#include "../../fsl-mc/include/mc-sys.h"
230 +#include "../../fsl-mc/include/mc-cmd.h"
232 +#include "dpmac-cmd.h"
235 + * dpmac_open() - Open a control session for the specified object.
236 + * @mc_io: Pointer to MC portal's I/O object
237 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
238 + * @dpmac_id: DPMAC unique ID
239 + * @token: Returned token; use in subsequent API calls
241 + * This function can be used to open a control session for an
242 + * already created object; an object may have been declared in
243 + * the DPL or by calling the dpmac_create function.
244 + * This function returns a unique authentication token,
245 + * associated with the specific object ID and the specific MC
246 + * portal; this token must be used in all subsequent commands for
247 + * this specific object
249 + * Return: '0' on Success; Error code otherwise.
251 +int dpmac_open(struct fsl_mc_io *mc_io,
256 + struct dpmac_cmd_open *cmd_params;
257 + struct mc_command cmd = { 0 };
260 + /* prepare command */
261 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_OPEN,
264 + cmd_params = (struct dpmac_cmd_open *)cmd.params;
265 + cmd_params->dpmac_id = cpu_to_le32(dpmac_id);
267 + /* send command to mc*/
268 + err = mc_send_command(mc_io, &cmd);
272 + /* retrieve response parameters */
273 + *token = mc_cmd_hdr_read_token(&cmd);
279 + * dpmac_close() - Close the control session of the object
280 + * @mc_io: Pointer to MC portal's I/O object
281 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
282 + * @token: Token of DPMAC object
284 + * After this function is called, no further operations are
285 + * allowed on the object without opening a new control session.
287 + * Return: '0' on Success; Error code otherwise.
289 +int dpmac_close(struct fsl_mc_io *mc_io,
293 + struct mc_command cmd = { 0 };
295 + /* prepare command */
296 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_CLOSE, cmd_flags,
299 + /* send command to mc*/
300 + return mc_send_command(mc_io, &cmd);
304 + * dpmac_create() - Create the DPMAC object.
305 + * @mc_io: Pointer to MC portal's I/O object
306 + * @dprc_token: Parent container token; '0' for default container
307 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
308 + * @cfg: Configuration structure
309 + * @obj_id: Returned object id
311 + * Create the DPMAC object, allocate required resources and
312 + * perform required initialization.
314 + * The function accepts an authentication token of a parent
315 + * container that this object should be assigned to. The token
316 + * can be '0' so the object will be assigned to the default container.
317 + * The newly created object can be opened with the returned
318 + * object id and using the container's associated tokens and MC portals.
320 + * Return: '0' on Success; Error code otherwise.
322 +int dpmac_create(struct fsl_mc_io *mc_io,
325 + const struct dpmac_cfg *cfg,
328 + struct dpmac_cmd_create *cmd_params;
329 + struct mc_command cmd = { 0 };
332 + /* prepare command */
333 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_CREATE,
336 + cmd_params = (struct dpmac_cmd_create *)cmd.params;
337 + cmd_params->mac_id = cpu_to_le32(cfg->mac_id);
339 + /* send command to mc*/
340 + err = mc_send_command(mc_io, &cmd);
344 + /* retrieve response parameters */
345 + *obj_id = mc_cmd_read_object_id(&cmd);
351 + * dpmac_destroy() - Destroy the DPMAC object and release all its resources.
352 + * @mc_io: Pointer to MC portal's I/O object
353 + * @dprc_token: Parent container token; '0' for default container
354 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
355 + * @object_id: The object id; it must be a valid id within the container that
356 + * created this object;
358 + * The function accepts the authentication token of the parent container that
359 + * created the object (not the one that currently owns the object). The object
360 + * is searched within parent using the provided 'object_id'.
361 + * All tokens to the object must be closed before calling destroy.
363 + * Return: '0' on Success; error code otherwise.
365 +int dpmac_destroy(struct fsl_mc_io *mc_io,
370 + struct dpmac_cmd_destroy *cmd_params;
371 + struct mc_command cmd = { 0 };
373 + /* prepare command */
374 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_DESTROY,
377 + cmd_params = (struct dpmac_cmd_destroy *)cmd.params;
378 + cmd_params->dpmac_id = cpu_to_le32(object_id);
380 + /* send command to mc*/
381 + return mc_send_command(mc_io, &cmd);
385 + * dpmac_set_irq_enable() - Set overall interrupt state.
386 + * @mc_io: Pointer to MC portal's I/O object
387 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
388 + * @token: Token of DPMAC object
389 + * @irq_index: The interrupt index to configure
390 + * @en: Interrupt state - enable = 1, disable = 0
392 + * Allows GPP software to control when interrupts are generated.
393 + * Each interrupt can have up to 32 causes. The enable/disable control's the
394 + * overall interrupt state. if the interrupt is disabled no causes will cause
397 + * Return: '0' on Success; Error code otherwise.
399 +int dpmac_set_irq_enable(struct fsl_mc_io *mc_io,
405 + struct dpmac_cmd_set_irq_enable *cmd_params;
406 + struct mc_command cmd = { 0 };
408 + /* prepare command */
409 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_IRQ_ENABLE,
412 + cmd_params = (struct dpmac_cmd_set_irq_enable *)cmd.params;
413 + cmd_params->irq_index = irq_index;
414 + cmd_params->enable = en;
416 + /* send command to mc*/
417 + return mc_send_command(mc_io, &cmd);
421 + * dpmac_get_irq_enable() - Get overall interrupt state
422 + * @mc_io: Pointer to MC portal's I/O object
423 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
424 + * @token: Token of DPMAC object
425 + * @irq_index: The interrupt index to configure
426 + * @en: Returned interrupt state - enable = 1, disable = 0
428 + * Return: '0' on Success; Error code otherwise.
430 +int dpmac_get_irq_enable(struct fsl_mc_io *mc_io,
436 + struct dpmac_cmd_get_irq_enable *cmd_params;
437 + struct dpmac_rsp_get_irq_enable *rsp_params;
438 + struct mc_command cmd = { 0 };
441 + /* prepare command */
442 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_IRQ_ENABLE,
445 + cmd_params = (struct dpmac_cmd_get_irq_enable *)cmd.params;
446 + cmd_params->irq_index = irq_index;
448 + /* send command to mc*/
449 + err = mc_send_command(mc_io, &cmd);
453 + /* retrieve response parameters */
454 + rsp_params = (struct dpmac_rsp_get_irq_enable *)cmd.params;
455 + *en = rsp_params->enabled;
461 + * dpmac_set_irq_mask() - Set interrupt mask.
462 + * @mc_io: Pointer to MC portal's I/O object
463 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
464 + * @token: Token of DPMAC object
465 + * @irq_index: The interrupt index to configure
466 + * @mask: Event mask to trigger interrupt;
469 + * 1 = consider event for asserting IRQ
471 + * Every interrupt can have up to 32 causes and the interrupt model supports
472 + * masking/unmasking each cause independently
474 + * Return: '0' on Success; Error code otherwise.
476 +int dpmac_set_irq_mask(struct fsl_mc_io *mc_io,
482 + struct dpmac_cmd_set_irq_mask *cmd_params;
483 + struct mc_command cmd = { 0 };
485 + /* prepare command */
486 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_IRQ_MASK,
489 + cmd_params = (struct dpmac_cmd_set_irq_mask *)cmd.params;
490 + cmd_params->mask = cpu_to_le32(mask);
491 + cmd_params->irq_index = irq_index;
493 + /* send command to mc*/
494 + return mc_send_command(mc_io, &cmd);
498 + * dpmac_get_irq_mask() - Get interrupt mask.
499 + * @mc_io: Pointer to MC portal's I/O object
500 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
501 + * @token: Token of DPMAC object
502 + * @irq_index: The interrupt index to configure
503 + * @mask: Returned event mask to trigger interrupt
505 + * Every interrupt can have up to 32 causes and the interrupt model supports
506 + * masking/unmasking each cause independently
508 + * Return: '0' on Success; Error code otherwise.
510 +int dpmac_get_irq_mask(struct fsl_mc_io *mc_io,
516 + struct dpmac_cmd_get_irq_mask *cmd_params;
517 + struct dpmac_rsp_get_irq_mask *rsp_params;
518 + struct mc_command cmd = { 0 };
521 + /* prepare command */
522 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_IRQ_MASK,
525 + cmd_params = (struct dpmac_cmd_get_irq_mask *)cmd.params;
526 + cmd_params->irq_index = irq_index;
528 + /* send command to mc*/
529 + err = mc_send_command(mc_io, &cmd);
533 + /* retrieve response parameters */
534 + rsp_params = (struct dpmac_rsp_get_irq_mask *)cmd.params;
535 + *mask = le32_to_cpu(rsp_params->mask);
541 + * dpmac_get_irq_status() - Get the current status of any pending interrupts.
543 + * @mc_io: Pointer to MC portal's I/O object
544 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
545 + * @token: Token of DPMAC object
546 + * @irq_index: The interrupt index to configure
547 + * @status: Returned interrupts status - one bit per cause:
548 + * 0 = no interrupt pending
549 + * 1 = interrupt pending
551 + * Return: '0' on Success; Error code otherwise.
553 +int dpmac_get_irq_status(struct fsl_mc_io *mc_io,
559 + struct dpmac_cmd_get_irq_status *cmd_params;
560 + struct dpmac_rsp_get_irq_status *rsp_params;
561 + struct mc_command cmd = { 0 };
564 + /* prepare command */
565 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_IRQ_STATUS,
568 + cmd_params = (struct dpmac_cmd_get_irq_status *)cmd.params;
569 + cmd_params->status = cpu_to_le32(*status);
570 + cmd_params->irq_index = irq_index;
572 + /* send command to mc*/
573 + err = mc_send_command(mc_io, &cmd);
577 + /* retrieve response parameters */
578 + rsp_params = (struct dpmac_rsp_get_irq_status *)cmd.params;
579 + *status = le32_to_cpu(rsp_params->status);
585 + * dpmac_clear_irq_status() - Clear a pending interrupt's status
587 + * @mc_io: Pointer to MC portal's I/O object
588 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
589 + * @token: Token of DPMAC object
590 + * @irq_index: The interrupt index to configure
591 + * @status: Bits to clear (W1C) - one bit per cause:
593 + * 1 = clear status bit
595 + * Return: '0' on Success; Error code otherwise.
597 +int dpmac_clear_irq_status(struct fsl_mc_io *mc_io,
603 + struct dpmac_cmd_clear_irq_status *cmd_params;
604 + struct mc_command cmd = { 0 };
606 + /* prepare command */
607 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_CLEAR_IRQ_STATUS,
610 + cmd_params = (struct dpmac_cmd_clear_irq_status *)cmd.params;
611 + cmd_params->status = cpu_to_le32(status);
612 + cmd_params->irq_index = irq_index;
614 + /* send command to mc*/
615 + return mc_send_command(mc_io, &cmd);
619 + * dpmac_get_attributes - Retrieve DPMAC attributes.
621 + * @mc_io: Pointer to MC portal's I/O object
622 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
623 + * @token: Token of DPMAC object
624 + * @attr: Returned object's attributes
626 + * Return: '0' on Success; Error code otherwise.
628 +int dpmac_get_attributes(struct fsl_mc_io *mc_io,
631 + struct dpmac_attr *attr)
633 + struct dpmac_rsp_get_attributes *rsp_params;
634 + struct mc_command cmd = { 0 };
637 + /* prepare command */
638 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_ATTR,
642 + /* send command to mc*/
643 + err = mc_send_command(mc_io, &cmd);
647 + /* retrieve response parameters */
648 + rsp_params = (struct dpmac_rsp_get_attributes *)cmd.params;
649 + attr->eth_if = rsp_params->eth_if;
650 + attr->link_type = rsp_params->link_type;
651 + attr->id = le16_to_cpu(rsp_params->id);
652 + attr->max_rate = le32_to_cpu(rsp_params->max_rate);
658 + * dpmac_get_link_cfg() - Get Ethernet link configuration
659 + * @mc_io: Pointer to opaque I/O object
660 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
661 + * @token: Token of DPMAC object
662 + * @cfg: Returned structure with the link configuration
664 + * Return: '0' on Success; Error code otherwise.
666 +int dpmac_get_link_cfg(struct fsl_mc_io *mc_io,
669 + struct dpmac_link_cfg *cfg)
671 + struct dpmac_rsp_get_link_cfg *rsp_params;
672 + struct mc_command cmd = { 0 };
675 + /* prepare command */
676 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_LINK_CFG,
680 + /* send command to mc*/
681 + err = mc_send_command(mc_io, &cmd);
685 + rsp_params = (struct dpmac_rsp_get_link_cfg *)cmd.params;
686 + cfg->options = le64_to_cpu(rsp_params->options);
687 + cfg->rate = le32_to_cpu(rsp_params->rate);
693 + * dpmac_set_link_state() - Set the Ethernet link status
694 + * @mc_io: Pointer to opaque I/O object
695 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
696 + * @token: Token of DPMAC object
697 + * @link_state: Link state configuration
699 + * Return: '0' on Success; Error code otherwise.
701 +int dpmac_set_link_state(struct fsl_mc_io *mc_io,
704 + struct dpmac_link_state *link_state)
706 + struct dpmac_cmd_set_link_state *cmd_params;
707 + struct mc_command cmd = { 0 };
709 + /* prepare command */
710 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_LINK_STATE,
713 + cmd_params = (struct dpmac_cmd_set_link_state *)cmd.params;
714 + cmd_params->options = cpu_to_le64(link_state->options);
715 + cmd_params->rate = cpu_to_le32(link_state->rate);
716 + cmd_params->up = dpmac_get_field(link_state->up, STATE);
718 + /* send command to mc*/
719 + return mc_send_command(mc_io, &cmd);
723 + * dpmac_get_counter() - Read a specific DPMAC counter
724 + * @mc_io: Pointer to opaque I/O object
725 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
726 + * @token: Token of DPMAC object
727 + * @type: The requested counter
728 + * @counter: Returned counter value
730 + * Return: The requested counter; '0' otherwise.
732 +int dpmac_get_counter(struct fsl_mc_io *mc_io,
735 + enum dpmac_counter type,
738 + struct dpmac_cmd_get_counter *dpmac_cmd;
739 + struct dpmac_rsp_get_counter *dpmac_rsp;
740 + struct mc_command cmd = { 0 };
743 + /* prepare command */
744 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_COUNTER,
747 + dpmac_cmd = (struct dpmac_cmd_get_counter *)cmd.params;
748 + dpmac_cmd->type = type;
750 + /* send command to mc*/
751 + err = mc_send_command(mc_io, &cmd);
755 + dpmac_rsp = (struct dpmac_rsp_get_counter *)cmd.params;
756 + *counter = le64_to_cpu(dpmac_rsp->counter);
762 +int dpmac_set_port_mac_addr(struct fsl_mc_io *mc_io,
767 + struct dpmac_cmd_set_port_mac_addr *dpmac_cmd;
768 + struct mc_command cmd = { 0 };
770 + /* prepare command */
771 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_PORT_MAC_ADDR,
774 + dpmac_cmd = (struct dpmac_cmd_set_port_mac_addr *)cmd.params;
775 + dpmac_cmd->addr[0] = addr[5];
776 + dpmac_cmd->addr[1] = addr[4];
777 + dpmac_cmd->addr[2] = addr[3];
778 + dpmac_cmd->addr[3] = addr[2];
779 + dpmac_cmd->addr[4] = addr[1];
780 + dpmac_cmd->addr[5] = addr[0];
782 + /* send command to mc*/
783 + return mc_send_command(mc_io, &cmd);
787 + * dpmac_get_api_version() - Get Data Path MAC version
788 + * @mc_io: Pointer to MC portal's I/O object
789 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
790 + * @major_ver: Major version of data path mac API
791 + * @minor_ver: Minor version of data path mac API
793 + * Return: '0' on Success; Error code otherwise.
795 +int dpmac_get_api_version(struct fsl_mc_io *mc_io,
800 + struct dpmac_rsp_get_api_version *rsp_params;
801 + struct mc_command cmd = { 0 };
804 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_API_VERSION,
808 + err = mc_send_command(mc_io, &cmd);
812 + rsp_params = (struct dpmac_rsp_get_api_version *)cmd.params;
813 + *major_ver = le16_to_cpu(rsp_params->major);
814 + *minor_ver = le16_to_cpu(rsp_params->minor);
819 +++ b/drivers/staging/fsl-dpaa2/mac/dpmac.h
821 +/* Copyright 2013-2016 Freescale Semiconductor Inc.
823 + * Redistribution and use in source and binary forms, with or without
824 + * modification, are permitted provided that the following conditions are met:
825 + * * Redistributions of source code must retain the above copyright
826 + * notice, this list of conditions and the following disclaimer.
827 + * * Redistributions in binary form must reproduce the above copyright
828 + * notice, this list of conditions and the following disclaimer in the
829 + * documentation and/or other materials provided with the distribution.
830 + * * Neither the name of the above-listed copyright holders nor the
831 + * names of any contributors may be used to endorse or promote products
832 + * derived from this software without specific prior written permission.
835 + * ALTERNATIVELY, this software may be distributed under the terms of the
836 + * GNU General Public License ("GPL") as published by the Free Software
837 + * Foundation, either version 2 of that License or (at your option) any
840 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
841 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
842 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
843 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
844 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
845 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
846 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
847 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
848 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
849 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
850 + * POSSIBILITY OF SUCH DAMAGE.
852 +#ifndef __FSL_DPMAC_H
853 +#define __FSL_DPMAC_H
855 +/* Data Path MAC API
856 + * Contains initialization APIs and runtime control APIs for DPMAC
861 +int dpmac_open(struct fsl_mc_io *mc_io,
866 +int dpmac_close(struct fsl_mc_io *mc_io,
871 + * enum dpmac_link_type - DPMAC link type
872 + * @DPMAC_LINK_TYPE_NONE: No link
873 + * @DPMAC_LINK_TYPE_FIXED: Link is fixed type
874 + * @DPMAC_LINK_TYPE_PHY: Link by PHY ID
875 + * @DPMAC_LINK_TYPE_BACKPLANE: Backplane link type
877 +enum dpmac_link_type {
878 + DPMAC_LINK_TYPE_NONE,
879 + DPMAC_LINK_TYPE_FIXED,
880 + DPMAC_LINK_TYPE_PHY,
881 + DPMAC_LINK_TYPE_BACKPLANE
885 + * enum dpmac_eth_if - DPMAC Ethrnet interface
886 + * @DPMAC_ETH_IF_MII: MII interface
887 + * @DPMAC_ETH_IF_RMII: RMII interface
888 + * @DPMAC_ETH_IF_SMII: SMII interface
889 + * @DPMAC_ETH_IF_GMII: GMII interface
890 + * @DPMAC_ETH_IF_RGMII: RGMII interface
891 + * @DPMAC_ETH_IF_SGMII: SGMII interface
892 + * @DPMAC_ETH_IF_QSGMII: QSGMII interface
893 + * @DPMAC_ETH_IF_XAUI: XAUI interface
894 + * @DPMAC_ETH_IF_XFI: XFI interface
901 + DPMAC_ETH_IF_RGMII,
902 + DPMAC_ETH_IF_SGMII,
903 + DPMAC_ETH_IF_QSGMII,
909 + * struct dpmac_cfg - Structure representing DPMAC configuration
910 + * @mac_id: Represents the Hardware MAC ID; in case of multiple WRIOP,
911 + * the MAC IDs are continuous.
912 + * For example: 2 WRIOPs, 16 MACs in each:
913 + * MAC IDs for the 1st WRIOP: 1-16,
914 + * MAC IDs for the 2nd WRIOP: 17-32.
920 +int dpmac_create(struct fsl_mc_io *mc_io,
923 + const struct dpmac_cfg *cfg,
926 +int dpmac_destroy(struct fsl_mc_io *mc_io,
932 + * DPMAC IRQ Index and Events
938 +#define DPMAC_IRQ_INDEX 0
940 + * IRQ event - indicates a change in link state
942 +#define DPMAC_IRQ_EVENT_LINK_CFG_REQ 0x00000001
944 + * IRQ event - Indicates that the link state changed
946 +#define DPMAC_IRQ_EVENT_LINK_CHANGED 0x00000002
948 +int dpmac_set_irq_enable(struct fsl_mc_io *mc_io,
954 +int dpmac_get_irq_enable(struct fsl_mc_io *mc_io,
960 +int dpmac_set_irq_mask(struct fsl_mc_io *mc_io,
966 +int dpmac_get_irq_mask(struct fsl_mc_io *mc_io,
972 +int dpmac_get_irq_status(struct fsl_mc_io *mc_io,
978 +int dpmac_clear_irq_status(struct fsl_mc_io *mc_io,
985 + * struct dpmac_attr - Structure representing DPMAC attributes
986 + * @id: DPMAC object ID
987 + * @max_rate: Maximum supported rate - in Mbps
988 + * @eth_if: Ethernet interface
989 + * @link_type: link type
994 + enum dpmac_eth_if eth_if;
995 + enum dpmac_link_type link_type;
998 +int dpmac_get_attributes(struct fsl_mc_io *mc_io,
1001 + struct dpmac_attr *attr);
1004 + * DPMAC link configuration/state options
1008 + * Enable auto-negotiation
1010 +#define DPMAC_LINK_OPT_AUTONEG 0x0000000000000001ULL
1012 + * Enable half-duplex mode
1014 +#define DPMAC_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
1016 + * Enable pause frames
1018 +#define DPMAC_LINK_OPT_PAUSE 0x0000000000000004ULL
1020 + * Enable a-symmetric pause frames
1022 +#define DPMAC_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
1025 + * struct dpmac_link_cfg - Structure representing DPMAC link configuration
1026 + * @rate: Link's rate - in Mbps
1027 + * @options: Enable/Disable DPMAC link cfg features (bitmap)
1029 +struct dpmac_link_cfg {
1034 +int dpmac_get_link_cfg(struct fsl_mc_io *mc_io,
1037 + struct dpmac_link_cfg *cfg);
1040 + * struct dpmac_link_state - DPMAC link configuration request
1041 + * @rate: Rate in Mbps
1042 + * @options: Enable/Disable DPMAC link cfg features (bitmap)
1045 +struct dpmac_link_state {
1051 +int dpmac_set_link_state(struct fsl_mc_io *mc_io,
1054 + struct dpmac_link_state *link_state);
1057 + * enum dpmac_counter - DPMAC counter types
1058 + * @DPMAC_CNT_ING_FRAME_64: counts 64-bytes frames, good or bad.
1059 + * @DPMAC_CNT_ING_FRAME_127: counts 65- to 127-bytes frames, good or bad.
1060 + * @DPMAC_CNT_ING_FRAME_255: counts 128- to 255-bytes frames, good or bad.
1061 + * @DPMAC_CNT_ING_FRAME_511: counts 256- to 511-bytes frames, good or bad.
1062 + * @DPMAC_CNT_ING_FRAME_1023: counts 512- to 1023-bytes frames, good or bad.
1063 + * @DPMAC_CNT_ING_FRAME_1518: counts 1024- to 1518-bytes frames, good or bad.
1064 + * @DPMAC_CNT_ING_FRAME_1519_MAX: counts 1519-bytes frames and larger
1065 + * (up to max frame length specified),
1067 + * @DPMAC_CNT_ING_FRAG: counts frames which are shorter than 64 bytes received
1068 + * with a wrong CRC
1069 + * @DPMAC_CNT_ING_JABBER: counts frames longer than the maximum frame length
1070 + * specified, with a bad frame check sequence.
1071 + * @DPMAC_CNT_ING_FRAME_DISCARD: counts dropped frames due to internal errors.
1072 + * Occurs when a receive FIFO overflows.
1073 + * Includes also frames truncated as a result of
1074 + * the receive FIFO overflow.
1075 + * @DPMAC_CNT_ING_ALIGN_ERR: counts frames with an alignment error
1076 + * (optional used for wrong SFD).
1077 + * @DPMAC_CNT_EGR_UNDERSIZED: counts frames transmitted that was less than 64
1078 + * bytes long with a good CRC.
1079 + * @DPMAC_CNT_ING_OVERSIZED: counts frames longer than the maximum frame length
1080 + * specified, with a good frame check sequence.
1081 + * @DPMAC_CNT_ING_VALID_PAUSE_FRAME: counts valid pause frames (regular and PFC)
1082 + * @DPMAC_CNT_EGR_VALID_PAUSE_FRAME: counts valid pause frames transmitted
1083 + * (regular and PFC).
1084 + * @DPMAC_CNT_ING_BYTE: counts bytes received except preamble for all valid
1085 + * frames and valid pause frames.
1086 + * @DPMAC_CNT_ING_MCAST_FRAME: counts received multicast frames.
1087 + * @DPMAC_CNT_ING_BCAST_FRAME: counts received broadcast frames.
1088 + * @DPMAC_CNT_ING_ALL_FRAME: counts each good or bad frames received.
1089 + * @DPMAC_CNT_ING_UCAST_FRAME: counts received unicast frames.
1090 + * @DPMAC_CNT_ING_ERR_FRAME: counts frames received with an error
1091 + * (except for undersized/fragment frame).
1092 + * @DPMAC_CNT_EGR_BYTE: counts bytes transmitted except preamble for all valid
1093 + * frames and valid pause frames transmitted.
1094 + * @DPMAC_CNT_EGR_MCAST_FRAME: counts transmitted multicast frames.
1095 + * @DPMAC_CNT_EGR_BCAST_FRAME: counts transmitted broadcast frames.
1096 + * @DPMAC_CNT_EGR_UCAST_FRAME: counts transmitted unicast frames.
1097 + * @DPMAC_CNT_EGR_ERR_FRAME: counts frames transmitted with an error.
1098 + * @DPMAC_CNT_ING_GOOD_FRAME: counts frames received without error, including
1100 + * @DPMAC_CNT_ENG_GOOD_FRAME: counts frames transmitted without error, including
1103 +enum dpmac_counter {
1104 + DPMAC_CNT_ING_FRAME_64,
1105 + DPMAC_CNT_ING_FRAME_127,
1106 + DPMAC_CNT_ING_FRAME_255,
1107 + DPMAC_CNT_ING_FRAME_511,
1108 + DPMAC_CNT_ING_FRAME_1023,
1109 + DPMAC_CNT_ING_FRAME_1518,
1110 + DPMAC_CNT_ING_FRAME_1519_MAX,
1111 + DPMAC_CNT_ING_FRAG,
1112 + DPMAC_CNT_ING_JABBER,
1113 + DPMAC_CNT_ING_FRAME_DISCARD,
1114 + DPMAC_CNT_ING_ALIGN_ERR,
1115 + DPMAC_CNT_EGR_UNDERSIZED,
1116 + DPMAC_CNT_ING_OVERSIZED,
1117 + DPMAC_CNT_ING_VALID_PAUSE_FRAME,
1118 + DPMAC_CNT_EGR_VALID_PAUSE_FRAME,
1119 + DPMAC_CNT_ING_BYTE,
1120 + DPMAC_CNT_ING_MCAST_FRAME,
1121 + DPMAC_CNT_ING_BCAST_FRAME,
1122 + DPMAC_CNT_ING_ALL_FRAME,
1123 + DPMAC_CNT_ING_UCAST_FRAME,
1124 + DPMAC_CNT_ING_ERR_FRAME,
1125 + DPMAC_CNT_EGR_BYTE,
1126 + DPMAC_CNT_EGR_MCAST_FRAME,
1127 + DPMAC_CNT_EGR_BCAST_FRAME,
1128 + DPMAC_CNT_EGR_UCAST_FRAME,
1129 + DPMAC_CNT_EGR_ERR_FRAME,
1130 + DPMAC_CNT_ING_GOOD_FRAME,
1131 + DPMAC_CNT_ENG_GOOD_FRAME
1134 +int dpmac_get_counter(struct fsl_mc_io *mc_io,
1137 + enum dpmac_counter type,
1141 + * dpmac_set_port_mac_addr() - Set a MAC address associated with the physical
1142 + * port. This is not used for filtering, MAC is always in
1143 + * promiscuous mode, it is passed to DPNIs through DPNI API for
1144 + * application used.
1145 + * @mc_io: Pointer to opaque I/O object
1146 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1147 + * @token: Token of DPMAC object
1148 + * @addr: MAC address to set
1150 + * Return: The requested counter; '0' otherwise.
1152 +int dpmac_set_port_mac_addr(struct fsl_mc_io *mc_io,
1155 + const u8 addr[6]);
1157 +int dpmac_get_api_version(struct fsl_mc_io *mc_io,
1162 +#endif /* __FSL_DPMAC_H */