123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181 |
- // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
- /* Copyright 2013-2016 Freescale Semiconductor Inc.
- * Copyright 2016 NXP
- * Copyright 2020 NXP
- */
- #include <linux/kernel.h>
- #include <linux/errno.h>
- #include <linux/fsl/mc.h>
- #include "dpni.h"
- #include "dpni-cmd.h"
- /**
- * dpni_prepare_key_cfg() - function prepare extract parameters
- * @cfg: defining a full Key Generation profile (rule)
- * @key_cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
- *
- * This function has to be called before the following functions:
- * - dpni_set_rx_tc_dist()
- * - dpni_set_qos_table()
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg, u8 *key_cfg_buf)
- {
- int i, j;
- struct dpni_ext_set_rx_tc_dist *dpni_ext;
- struct dpni_dist_extract *extr;
- if (cfg->num_extracts > DPKG_MAX_NUM_OF_EXTRACTS)
- return -EINVAL;
- dpni_ext = (struct dpni_ext_set_rx_tc_dist *)key_cfg_buf;
- dpni_ext->num_extracts = cfg->num_extracts;
- for (i = 0; i < cfg->num_extracts; i++) {
- extr = &dpni_ext->extracts[i];
- switch (cfg->extracts[i].type) {
- case DPKG_EXTRACT_FROM_HDR:
- extr->prot = cfg->extracts[i].extract.from_hdr.prot;
- dpni_set_field(extr->efh_type, EFH_TYPE,
- cfg->extracts[i].extract.from_hdr.type);
- extr->size = cfg->extracts[i].extract.from_hdr.size;
- extr->offset = cfg->extracts[i].extract.from_hdr.offset;
- extr->field = cpu_to_le32(
- cfg->extracts[i].extract.from_hdr.field);
- extr->hdr_index =
- cfg->extracts[i].extract.from_hdr.hdr_index;
- break;
- case DPKG_EXTRACT_FROM_DATA:
- extr->size = cfg->extracts[i].extract.from_data.size;
- extr->offset =
- cfg->extracts[i].extract.from_data.offset;
- break;
- case DPKG_EXTRACT_FROM_PARSE:
- extr->size = cfg->extracts[i].extract.from_parse.size;
- extr->offset =
- cfg->extracts[i].extract.from_parse.offset;
- break;
- default:
- return -EINVAL;
- }
- extr->num_of_byte_masks = cfg->extracts[i].num_of_byte_masks;
- dpni_set_field(extr->extract_type, EXTRACT_TYPE,
- cfg->extracts[i].type);
- for (j = 0; j < DPKG_NUM_OF_MASKS; j++) {
- extr->masks[j].mask = cfg->extracts[i].masks[j].mask;
- extr->masks[j].offset =
- cfg->extracts[i].masks[j].offset;
- }
- }
- return 0;
- }
- /**
- * dpni_open() - Open a control session for the specified object
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @dpni_id: DPNI unique ID
- * @token: Returned token; use in subsequent API calls
- *
- * This function can be used to open a control session for an
- * already created object; an object may have been declared in
- * the DPL or by calling the dpni_create() function.
- * This function returns a unique authentication token,
- * associated with the specific object ID and the specific MC
- * portal; this token must be used in all subsequent commands for
- * this specific object.
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_open(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- int dpni_id,
- u16 *token)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_open *cmd_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
- cmd_flags,
- 0);
- cmd_params = (struct dpni_cmd_open *)cmd.params;
- cmd_params->dpni_id = cpu_to_le32(dpni_id);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- *token = mc_cmd_hdr_read_token(&cmd);
- return 0;
- }
- /**
- * dpni_close() - Close the control session of the object
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- *
- * After this function is called, no further operations are
- * allowed on the object without opening a new control session.
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_close(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token)
- {
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
- cmd_flags,
- token);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_set_pools() - Set buffer pools configuration
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cfg: Buffer pools configuration
- *
- * mandatory for DPNI operation
- * warning:Allowed only when DPNI is disabled
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_pools(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const struct dpni_pools_cfg *cfg)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_pools *cmd_params;
- int i;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
- cmd_params->num_dpbp = cfg->num_dpbp;
- for (i = 0; i < DPNI_MAX_DPBP; i++) {
- cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
- cmd_params->buffer_size[i] =
- cpu_to_le16(cfg->pools[i].buffer_size);
- cmd_params->backup_pool_mask |=
- DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
- }
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_enable(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token)
- {
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
- cmd_flags,
- token);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_disable(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token)
- {
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
- cmd_flags,
- token);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_is_enabled() - Check if the DPNI is enabled.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @en: Returns '1' if object is enabled; '0' otherwise
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_is_enabled(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- int *en)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_rsp_is_enabled *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
- *en = dpni_get_field(rsp_params->enabled, ENABLE);
- return 0;
- }
- /**
- * dpni_reset() - Reset the DPNI, returns the object to initial state.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_reset(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token)
- {
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
- cmd_flags,
- token);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_set_irq_enable() - Set overall interrupt state.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @irq_index: The interrupt index to configure
- * @en: Interrupt state: - enable = 1, disable = 0
- *
- * Allows GPP software to control when interrupts are generated.
- * Each interrupt can have up to 32 causes. The enable/disable control's the
- * overall interrupt state. if the interrupt is disabled no causes will cause
- * an interrupt.
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 irq_index,
- u8 en)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_irq_enable *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
- dpni_set_field(cmd_params->enable, ENABLE, en);
- cmd_params->irq_index = irq_index;
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_irq_enable() - Get overall interrupt state
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @irq_index: The interrupt index to configure
- * @en: Returned interrupt state - enable = 1, disable = 0
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 irq_index,
- u8 *en)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_get_irq_enable *cmd_params;
- struct dpni_rsp_get_irq_enable *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
- cmd_params->irq_index = irq_index;
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
- *en = dpni_get_field(rsp_params->enabled, ENABLE);
- return 0;
- }
- /**
- * dpni_set_irq_mask() - Set interrupt mask.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @irq_index: The interrupt index to configure
- * @mask: event mask to trigger interrupt;
- * each bit:
- * 0 = ignore event
- * 1 = consider event for asserting IRQ
- *
- * Every interrupt can have up to 32 causes and the interrupt model supports
- * masking/unmasking each cause independently
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 irq_index,
- u32 mask)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_irq_mask *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
- cmd_params->mask = cpu_to_le32(mask);
- cmd_params->irq_index = irq_index;
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_irq_mask() - Get interrupt mask.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @irq_index: The interrupt index to configure
- * @mask: Returned event mask to trigger interrupt
- *
- * Every interrupt can have up to 32 causes and the interrupt model supports
- * masking/unmasking each cause independently
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 irq_index,
- u32 *mask)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_get_irq_mask *cmd_params;
- struct dpni_rsp_get_irq_mask *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
- cmd_params->irq_index = irq_index;
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
- *mask = le32_to_cpu(rsp_params->mask);
- return 0;
- }
- /**
- * dpni_get_irq_status() - Get the current status of any pending interrupts.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @irq_index: The interrupt index to configure
- * @status: Returned interrupts status - one bit per cause:
- * 0 = no interrupt pending
- * 1 = interrupt pending
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_irq_status(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 irq_index,
- u32 *status)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_get_irq_status *cmd_params;
- struct dpni_rsp_get_irq_status *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
- cmd_params->status = cpu_to_le32(*status);
- cmd_params->irq_index = irq_index;
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
- *status = le32_to_cpu(rsp_params->status);
- return 0;
- }
- /**
- * dpni_clear_irq_status() - Clear a pending interrupt's status
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @irq_index: The interrupt index to configure
- * @status: bits to clear (W1C) - one bit per cause:
- * 0 = don't change
- * 1 = clear status bit
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 irq_index,
- u32 status)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_clear_irq_status *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
- cmd_params->irq_index = irq_index;
- cmd_params->status = cpu_to_le32(status);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_attributes() - Retrieve DPNI attributes.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @attr: Object's attributes
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_attributes(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- struct dpni_attr *attr)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_rsp_get_attr *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
- attr->options = le32_to_cpu(rsp_params->options);
- attr->num_queues = rsp_params->num_queues;
- attr->num_tcs = rsp_params->num_tcs;
- attr->mac_filter_entries = rsp_params->mac_filter_entries;
- attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
- attr->qos_entries = rsp_params->qos_entries;
- attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
- attr->qos_key_size = rsp_params->qos_key_size;
- attr->fs_key_size = rsp_params->fs_key_size;
- attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
- return 0;
- }
- /**
- * dpni_set_errors_behavior() - Set errors behavior
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cfg: Errors configuration
- *
- * this function may be called numerous times with different
- * error masks
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- struct dpni_error_cfg *cfg)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_errors_behavior *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
- cmd_params->errors = cpu_to_le32(cfg->errors);
- dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
- dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @qtype: Type of queue to retrieve configuration for
- * @layout: Returns buffer layout attributes
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_queue_type qtype,
- struct dpni_buffer_layout *layout)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_get_buffer_layout *cmd_params;
- struct dpni_rsp_get_buffer_layout *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
- cmd_params->qtype = qtype;
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
- layout->pass_timestamp = dpni_get_field(rsp_params->flags, PASS_TS);
- layout->pass_parser_result = dpni_get_field(rsp_params->flags, PASS_PR);
- layout->pass_frame_status = dpni_get_field(rsp_params->flags, PASS_FS);
- layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
- layout->data_align = le16_to_cpu(rsp_params->data_align);
- layout->data_head_room = le16_to_cpu(rsp_params->head_room);
- layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
- return 0;
- }
- /**
- * dpni_set_buffer_layout() - Set buffer layout configuration.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @qtype: Type of queue this configuration applies to
- * @layout: Buffer layout configuration
- *
- * Return: '0' on Success; Error code otherwise.
- *
- * @warning Allowed only when DPNI is disabled
- */
- int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_queue_type qtype,
- const struct dpni_buffer_layout *layout)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_buffer_layout *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
- cmd_params->qtype = qtype;
- cmd_params->options = cpu_to_le16(layout->options);
- dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
- dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
- dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
- cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
- cmd_params->data_align = cpu_to_le16(layout->data_align);
- cmd_params->head_room = cpu_to_le16(layout->data_head_room);
- cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_set_offload() - Set DPNI offload configuration.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @type: Type of DPNI offload
- * @config: Offload configuration.
- * For checksum offloads, non-zero value enables the offload
- *
- * Return: '0' on Success; Error code otherwise.
- *
- * @warning Allowed only when DPNI is disabled
- */
- int dpni_set_offload(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_offload type,
- u32 config)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_offload *cmd_params;
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
- cmd_params->dpni_offload = type;
- cmd_params->config = cpu_to_le32(config);
- return mc_send_command(mc_io, &cmd);
- }
- int dpni_get_offload(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_offload type,
- u32 *config)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_get_offload *cmd_params;
- struct dpni_rsp_get_offload *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
- cmd_params->dpni_offload = type;
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
- *config = le32_to_cpu(rsp_params->config);
- return 0;
- }
- /**
- * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
- * for enqueue operations
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @qtype: Type of queue to receive QDID for
- * @qdid: Returned virtual QDID value that should be used as an argument
- * in all enqueue operations
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_qdid(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_queue_type qtype,
- u16 *qdid)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_get_qdid *cmd_params;
- struct dpni_rsp_get_qdid *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
- cmd_params->qtype = qtype;
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
- *qdid = le16_to_cpu(rsp_params->qdid);
- return 0;
- }
- /**
- * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @data_offset: Tx data offset (from start of buffer)
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u16 *data_offset)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_rsp_get_tx_data_offset *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
- *data_offset = le16_to_cpu(rsp_params->data_offset);
- return 0;
- }
- /**
- * dpni_set_link_cfg() - set the link configuration.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cfg: Link configuration
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const struct dpni_link_cfg *cfg)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_link_cfg *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_link_cfg *)cmd.params;
- cmd_params->rate = cpu_to_le32(cfg->rate);
- cmd_params->options = cpu_to_le64(cfg->options);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_link_cfg() - return the link configuration
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cfg: Link configuration from dpni object
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_link_cfg(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- struct dpni_link_cfg *cfg)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_link_cfg *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_CFG,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_cmd_link_cfg *)cmd.params;
- cfg->rate = le32_to_cpu(rsp_params->rate);
- cfg->options = le64_to_cpu(rsp_params->options);
- return err;
- }
- /**
- * dpni_get_link_state() - Return the link state (either up or down)
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @state: Returned link state;
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_link_state(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- struct dpni_link_state *state)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_rsp_get_link_state *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
- state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
- state->rate = le32_to_cpu(rsp_params->rate);
- state->options = le64_to_cpu(rsp_params->options);
- return 0;
- }
- /**
- * dpni_set_max_frame_length() - Set the maximum received frame length.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @max_frame_length: Maximum received frame length (in
- * bytes); frame is discarded if its
- * length exceeds this value
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u16 max_frame_length)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_max_frame_length *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
- cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_max_frame_length() - Get the maximum received frame length.
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @max_frame_length: Maximum received frame length (in
- * bytes); frame is discarded if its
- * length exceeds this value
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u16 *max_frame_length)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_rsp_get_max_frame_length *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
- *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
- return 0;
- }
- /**
- * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @en: Set to '1' to enable; '0' to disable
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- int en)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_multicast_promisc *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
- dpni_set_field(cmd_params->enable, ENABLE, en);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_multicast_promisc() - Get multicast promiscuous mode
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @en: Returns '1' if enabled; '0' otherwise
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- int *en)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_rsp_get_multicast_promisc *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
- *en = dpni_get_field(rsp_params->enabled, ENABLE);
- return 0;
- }
- /**
- * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @en: Set to '1' to enable; '0' to disable
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- int en)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_unicast_promisc *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
- dpni_set_field(cmd_params->enable, ENABLE, en);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_unicast_promisc() - Get unicast promiscuous mode
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @en: Returns '1' if enabled; '0' otherwise
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- int *en)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_rsp_get_unicast_promisc *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
- *en = dpni_get_field(rsp_params->enabled, ENABLE);
- return 0;
- }
- /**
- * dpni_set_primary_mac_addr() - Set the primary MAC address
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @mac_addr: MAC address to set as primary address
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const u8 mac_addr[6])
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_primary_mac_addr *cmd_params;
- int i;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
- for (i = 0; i < 6; i++)
- cmd_params->mac_addr[i] = mac_addr[5 - i];
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_primary_mac_addr() - Get the primary MAC address
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @mac_addr: Returned MAC address
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 mac_addr[6])
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_rsp_get_primary_mac_addr *rsp_params;
- int i, err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
- for (i = 0; i < 6; i++)
- mac_addr[5 - i] = rsp_params->mac_addr[i];
- return 0;
- }
- /**
- * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
- * port the DPNI is attached to
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @mac_addr: MAC address of the physical port, if any, otherwise 0
- *
- * The primary MAC address is not cleared by this operation.
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 mac_addr[6])
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_rsp_get_port_mac_addr *rsp_params;
- int i, err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
- cmd_flags,
- token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
- for (i = 0; i < 6; i++)
- mac_addr[5 - i] = rsp_params->mac_addr[i];
- return 0;
- }
- /**
- * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @en: Set to '1' to enable; '0' to disable
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u32 en)
- {
- struct dpni_cmd_enable_vlan_filter *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
- dpni_set_field(cmd_params->en, ENABLE, en);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_add_vlan_id() - Add VLAN ID filter
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @vlan_id: VLAN ID to add
- * @flags: 0 - tc_id and flow_id will be ignored.
- * Pkt with this vlan_id will be passed to the next
- * classification stages
- * DPNI_VLAN_SET_QUEUE_ACTION
- * Pkt with this vlan_id will be forward directly to
- * queue defined by the tc_id and flow_id
- *
- * @tc_id: Traffic class selection (0-7)
- * @flow_id: Selects the specific queue out of the set allocated for the
- * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_add_vlan_id(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
- u16 vlan_id, u8 flags, u8 tc_id, u8 flow_id)
- {
- struct dpni_cmd_vlan_id *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
- cmd_params->flags = flags;
- cmd_params->tc_id = tc_id;
- cmd_params->flow_id = flow_id;
- cmd_params->vlan_id = cpu_to_le16(vlan_id);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_remove_vlan_id() - Remove VLAN ID filter
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @vlan_id: VLAN ID to remove
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_remove_vlan_id(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
- u16 vlan_id)
- {
- struct dpni_cmd_vlan_id *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
- cmd_params->vlan_id = cpu_to_le16(vlan_id);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_add_mac_addr() - Add MAC address filter
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @mac_addr: MAC address to add
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const u8 mac_addr[6])
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_add_mac_addr *cmd_params;
- int i;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
- for (i = 0; i < 6; i++)
- cmd_params->mac_addr[i] = mac_addr[5 - i];
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_remove_mac_addr() - Remove MAC address filter
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @mac_addr: MAC address to remove
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const u8 mac_addr[6])
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_remove_mac_addr *cmd_params;
- int i;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
- for (i = 0; i < 6; i++)
- cmd_params->mac_addr[i] = mac_addr[5 - i];
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @unicast: Set to '1' to clear unicast addresses
- * @multicast: Set to '1' to clear multicast addresses
- *
- * The primary MAC address is not cleared by this operation.
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- int unicast,
- int multicast)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_clear_mac_filters *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
- dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
- dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @tc_id: Traffic class selection (0-7)
- * @cfg: Traffic class distribution configuration
- *
- * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpni_prepare_key_cfg()
- * first to prepare the key_cfg_iova parameter
- *
- * Return: '0' on Success; error code otherwise.
- */
- int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 tc_id,
- const struct dpni_rx_tc_dist_cfg *cfg)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_rx_tc_dist *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
- cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
- cmd_params->tc_id = tc_id;
- dpni_set_field(cmd_params->flags, DIST_MODE, cfg->dist_mode);
- dpni_set_field(cmd_params->flags, MISS_ACTION, cfg->fs_cfg.miss_action);
- cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
- cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_set_congestion_notification() - Set traffic class congestion
- * notification configuration
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
- * @tc_id: Traffic class selection (0-7)
- * @cfg: Congestion notification configuration
- *
- * Return: '0' on Success; error code otherwise.
- */
- int dpni_set_congestion_notification(
- struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_queue_type qtype,
- u8 tc_id,
- const struct dpni_congestion_notification_cfg *cfg)
- {
- struct dpni_cmd_set_congestion_notification *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header =
- mc_encode_cmd_header(DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
- cmd_params->qtype = qtype;
- cmd_params->tc = tc_id;
- cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
- cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
- cmd_params->dest_priority = cfg->dest_cfg.priority;
- dpni_set_field(cmd_params->type_units, DEST_TYPE,
- cfg->dest_cfg.dest_type);
- dpni_set_field(cmd_params->type_units, CONG_UNITS, cfg->units);
- cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
- cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
- cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
- cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_set_queue() - Set queue parameters
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @qtype: Type of queue - all queue types are supported, although
- * the command is ignored for Tx
- * @tc: Traffic class, in range 0 to NUM_TCS - 1
- * @index: Selects the specific queue out of the set allocated for the
- * same TC. Value must be in range 0 to NUM_QUEUES - 1
- * @options: A combination of DPNI_QUEUE_OPT_ values that control what
- * configuration options are set on the queue
- * @queue: Queue structure
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_queue(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_queue_type qtype,
- u8 tc,
- u8 index,
- u8 options,
- const struct dpni_queue *queue)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_queue *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
- cmd_params->qtype = qtype;
- cmd_params->tc = tc;
- cmd_params->index = index;
- cmd_params->options = options;
- cmd_params->dest_id = cpu_to_le32(queue->destination.id);
- cmd_params->dest_prio = queue->destination.priority;
- dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
- dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
- dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
- queue->destination.hold_active);
- cmd_params->flc = cpu_to_le64(queue->flc.value);
- cmd_params->user_context = cpu_to_le64(queue->user_context);
- /* send command to mc */
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_queue() - Get queue parameters
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @qtype: Type of queue - all queue types are supported
- * @tc: Traffic class, in range 0 to NUM_TCS - 1
- * @index: Selects the specific queue out of the set allocated for the
- * same TC. Value must be in range 0 to NUM_QUEUES - 1
- * @queue: Queue configuration structure
- * @qid: Queue identification
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_queue(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_queue_type qtype,
- u8 tc,
- u8 index,
- struct dpni_queue *queue,
- struct dpni_queue_id *qid)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_get_queue *cmd_params;
- struct dpni_rsp_get_queue *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
- cmd_params->qtype = qtype;
- cmd_params->tc = tc;
- cmd_params->index = index;
- /* send command to mc */
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
- queue->destination.id = le32_to_cpu(rsp_params->dest_id);
- queue->destination.priority = rsp_params->dest_prio;
- queue->destination.type = dpni_get_field(rsp_params->flags,
- DEST_TYPE);
- queue->flc.stash_control = dpni_get_field(rsp_params->flags,
- STASH_CTRL);
- queue->destination.hold_active = dpni_get_field(rsp_params->flags,
- HOLD_ACTIVE);
- queue->flc.value = le64_to_cpu(rsp_params->flc);
- queue->user_context = le64_to_cpu(rsp_params->user_context);
- qid->fqid = le32_to_cpu(rsp_params->fqid);
- qid->qdbin = le16_to_cpu(rsp_params->qdbin);
- return 0;
- }
- /**
- * dpni_get_statistics() - Get DPNI statistics
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @page: Selects the statistics page to retrieve, see
- * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
- * @stat: Structure containing the statistics
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_statistics(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 page,
- union dpni_statistics *stat)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_get_statistics *cmd_params;
- struct dpni_rsp_get_statistics *rsp_params;
- int i, err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
- cmd_params->page_number = page;
- /* send command to mc */
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
- for (i = 0; i < DPNI_STATISTICS_CNT; i++)
- stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
- return 0;
- }
- /**
- * dpni_set_taildrop() - Set taildrop per queue or TC
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cg_point: Congestion point
- * @qtype: Queue type on which the taildrop is configured.
- * Only Rx queues are supported for now
- * @tc: Traffic class to apply this taildrop to
- * @index: Index of the queue if the DPNI supports multiple queues for
- * traffic distribution. Ignored if CONGESTION_POINT is not 0.
- * @taildrop: Taildrop structure
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_taildrop(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_congestion_point cg_point,
- enum dpni_queue_type qtype,
- u8 tc,
- u8 index,
- struct dpni_taildrop *taildrop)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_set_taildrop *cmd_params;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
- cmd_params->congestion_point = cg_point;
- cmd_params->qtype = qtype;
- cmd_params->tc = tc;
- cmd_params->index = index;
- dpni_set_field(cmd_params->enable, ENABLE, taildrop->enable);
- cmd_params->units = taildrop->units;
- cmd_params->threshold = cpu_to_le32(taildrop->threshold);
- /* send command to mc */
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_taildrop() - Get taildrop information
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cg_point: Congestion point
- * @qtype: Queue type on which the taildrop is configured.
- * Only Rx queues are supported for now
- * @tc: Traffic class to apply this taildrop to
- * @index: Index of the queue if the DPNI supports multiple queues for
- * traffic distribution. Ignored if CONGESTION_POINT is not 0.
- * @taildrop: Taildrop structure
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_taildrop(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- enum dpni_congestion_point cg_point,
- enum dpni_queue_type qtype,
- u8 tc,
- u8 index,
- struct dpni_taildrop *taildrop)
- {
- struct fsl_mc_command cmd = { 0 };
- struct dpni_cmd_get_taildrop *cmd_params;
- struct dpni_rsp_get_taildrop *rsp_params;
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
- cmd_params->congestion_point = cg_point;
- cmd_params->qtype = qtype;
- cmd_params->tc = tc;
- cmd_params->index = index;
- /* send command to mc */
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* retrieve response parameters */
- rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
- taildrop->enable = dpni_get_field(rsp_params->enable, ENABLE);
- taildrop->units = rsp_params->units;
- taildrop->threshold = le32_to_cpu(rsp_params->threshold);
- return 0;
- }
- /**
- * dpni_get_api_version() - Get Data Path Network Interface API version
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @major_ver: Major version of data path network interface API
- * @minor_ver: Minor version of data path network interface API
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_get_api_version(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 *major_ver,
- u16 *minor_ver)
- {
- struct dpni_rsp_get_api_version *rsp_params;
- struct fsl_mc_command cmd = { 0 };
- int err;
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
- cmd_flags, 0);
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
- *major_ver = le16_to_cpu(rsp_params->major);
- *minor_ver = le16_to_cpu(rsp_params->minor);
- return 0;
- }
- /**
- * dpni_set_rx_fs_dist() - Set Rx flow steering distribution
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cfg: Distribution configuration
- *
- * If the FS is already enabled with a previous call the classification
- * key will be changed but all the table rules are kept. If the
- * existing rules do not match the key the results will not be
- * predictable. It is the user responsibility to keep key integrity.
- * If cfg.enable is set to 1 the command will create a flow steering table
- * and will classify packets according to this table. The packets that
- * miss all the table rules will be classified according to settings
- * made in dpni_set_rx_hash_dist()
- * If cfg.enable is set to 0 the command will clear flow steering table.
- * The packets will be classified according to settings made in
- * dpni_set_rx_hash_dist()
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const struct dpni_rx_dist_cfg *cfg)
- {
- struct dpni_cmd_set_rx_fs_dist *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
- cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
- dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
- cmd_params->tc = cfg->tc;
- cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
- cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_set_rx_hash_dist() - Set Rx hash distribution
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cfg: Distribution configuration
- * If cfg.enable is set to 1 the packets will be classified using a hash
- * function based on the key received in cfg.key_cfg_iova parameter.
- * If cfg.enable is set to 0 the packets will be sent to the default queue
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const struct dpni_rx_dist_cfg *cfg)
- {
- struct dpni_cmd_set_rx_hash_dist *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
- cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
- dpni_set_field(cmd_params->enable, RX_HASH_DIST_ENABLE, cfg->enable);
- cmd_params->tc = cfg->tc;
- cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
- * (to select a flow ID)
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @tc_id: Traffic class selection (0-7)
- * @index: Location in the FS table where to insert the entry.
- * Only relevant if MASKING is enabled for FS
- * classification on this DPNI, it is ignored for exact match.
- * @cfg: Flow steering rule to add
- * @action: Action to be taken as result of a classification hit
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 tc_id,
- u16 index,
- const struct dpni_rule_cfg *cfg,
- const struct dpni_fs_action_cfg *action)
- {
- struct dpni_cmd_add_fs_entry *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
- cmd_params->tc_id = tc_id;
- cmd_params->key_size = cfg->key_size;
- cmd_params->index = cpu_to_le16(index);
- cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
- cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
- cmd_params->options = cpu_to_le16(action->options);
- cmd_params->flow_id = cpu_to_le16(action->flow_id);
- cmd_params->flc = cpu_to_le64(action->flc);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
- * traffic class
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @tc_id: Traffic class selection (0-7)
- * @cfg: Flow steering rule to remove
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- u8 tc_id,
- const struct dpni_rule_cfg *cfg)
- {
- struct dpni_cmd_remove_fs_entry *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
- cmd_params->tc_id = tc_id;
- cmd_params->key_size = cfg->key_size;
- cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
- cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_set_qos_table() - Set QoS mapping table
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cfg: QoS table configuration
- *
- * This function and all QoS-related functions require that
- *'max_tcs > 1' was set at DPNI creation.
- *
- * warning: Before calling this function, call dpkg_prepare_key_cfg() to
- * prepare the key_cfg_iova parameter
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_qos_table(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const struct dpni_qos_tbl_cfg *cfg)
- {
- struct dpni_cmd_set_qos_table *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
- cmd_params->default_tc = cfg->default_tc;
- cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
- dpni_set_field(cmd_params->discard_on_miss, DISCARD_ON_MISS,
- cfg->discard_on_miss);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cfg: QoS rule to add
- * @tc_id: Traffic class selection (0-7)
- * @index: Location in the QoS table where to insert the entry.
- * Only relevant if MASKING is enabled for QoS classification on
- * this DPNI, it is ignored for exact match.
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const struct dpni_rule_cfg *cfg,
- u8 tc_id,
- u16 index)
- {
- struct dpni_cmd_add_qos_entry *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
- cmd_params->tc_id = tc_id;
- cmd_params->key_size = cfg->key_size;
- cmd_params->index = cpu_to_le16(index);
- cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
- cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_remove_qos_entry() - Remove QoS mapping entry
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @cfg: QoS rule to remove
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const struct dpni_rule_cfg *cfg)
- {
- struct dpni_cmd_remove_qos_entry *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
- cmd_params->key_size = cfg->key_size;
- cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
- cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_clear_qos_table() - Clear all QoS mapping entries
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- *
- * Following this function call, all frames are directed to
- * the default traffic class (0)
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token)
- {
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
- cmd_flags,
- token);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_set_tx_shaping() - Set the transmit shaping
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @tx_cr_shaper: TX committed rate shaping configuration
- * @tx_er_shaper: TX excess rate shaping configuration
- * @coupled: Committed and excess rate shapers are coupled
- *
- * Return: '0' on Success; Error code otherwise.
- */
- int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- const struct dpni_tx_shaping_cfg *tx_cr_shaper,
- const struct dpni_tx_shaping_cfg *tx_er_shaper,
- int coupled)
- {
- struct dpni_cmd_set_tx_shaping *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
- cmd_flags,
- token);
- cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
- cmd_params->tx_cr_max_burst_size = cpu_to_le16(tx_cr_shaper->max_burst_size);
- cmd_params->tx_er_max_burst_size = cpu_to_le16(tx_er_shaper->max_burst_size);
- cmd_params->tx_cr_rate_limit = cpu_to_le32(tx_cr_shaper->rate_limit);
- cmd_params->tx_er_rate_limit = cpu_to_le32(tx_er_shaper->rate_limit);
- dpni_set_field(cmd_params->coupled, COUPLED, coupled);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
- /**
- * dpni_get_single_step_cfg() - return current configuration for
- * single step PTP
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @ptp_cfg: ptp single step configuration
- *
- * Return: '0' on Success; Error code otherwise.
- *
- */
- int dpni_get_single_step_cfg(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- struct dpni_single_step_cfg *ptp_cfg)
- {
- struct dpni_rsp_single_step_cfg *rsp_params;
- struct fsl_mc_command cmd = { 0 };
- int err;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SINGLE_STEP_CFG,
- cmd_flags, token);
- /* send command to mc*/
- err = mc_send_command(mc_io, &cmd);
- if (err)
- return err;
- /* read command response */
- rsp_params = (struct dpni_rsp_single_step_cfg *)cmd.params;
- ptp_cfg->offset = le16_to_cpu(rsp_params->offset);
- ptp_cfg->en = dpni_get_field(le16_to_cpu(rsp_params->flags),
- PTP_ENABLE) ? 1 : 0;
- ptp_cfg->ch_update = dpni_get_field(le16_to_cpu(rsp_params->flags),
- PTP_CH_UPDATE) ? 1 : 0;
- ptp_cfg->peer_delay = le32_to_cpu(rsp_params->peer_delay);
- ptp_cfg->ptp_onestep_reg_base =
- le32_to_cpu(rsp_params->ptp_onestep_reg_base);
- return err;
- }
- /**
- * dpni_set_single_step_cfg() - enable/disable and configure single step PTP
- * @mc_io: Pointer to MC portal's I/O object
- * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
- * @token: Token of DPNI object
- * @ptp_cfg: ptp single step configuration
- *
- * Return: '0' on Success; Error code otherwise.
- *
- * The function has effect only when dpni object is connected to a dpmac
- * object. If the dpni is not connected to a dpmac the configuration will
- * be stored inside and applied when connection is made.
- */
- int dpni_set_single_step_cfg(struct fsl_mc_io *mc_io,
- u32 cmd_flags,
- u16 token,
- struct dpni_single_step_cfg *ptp_cfg)
- {
- struct dpni_cmd_single_step_cfg *cmd_params;
- struct fsl_mc_command cmd = { 0 };
- u16 flags;
- /* prepare command */
- cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_SINGLE_STEP_CFG,
- cmd_flags, token);
- cmd_params = (struct dpni_cmd_single_step_cfg *)cmd.params;
- cmd_params->offset = cpu_to_le16(ptp_cfg->offset);
- cmd_params->peer_delay = cpu_to_le32(ptp_cfg->peer_delay);
- flags = le16_to_cpu(cmd_params->flags);
- dpni_set_field(flags, PTP_ENABLE, !!ptp_cfg->en);
- dpni_set_field(flags, PTP_CH_UPDATE, !!ptp_cfg->ch_update);
- cmd_params->flags = cpu_to_le16(flags);
- /* send command to mc*/
- return mc_send_command(mc_io, &cmd);
- }
|