12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144 |
- /*
- * Linux network driver for Brocade Converged Network Adapter.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License (GPL) Version 2 as
- * published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- */
- /*
- * Copyright (c) 2005-2011 Brocade Communications Systems, Inc.
- * All rights reserved
- * www.brocade.com
- */
- #include "bna.h"
- static inline int
- ethport_can_be_up(struct bna_ethport *ethport)
- {
- int ready = 0;
- if (ethport->bna->enet.type == BNA_ENET_T_REGULAR)
- ready = ((ethport->flags & BNA_ETHPORT_F_ADMIN_UP) &&
- (ethport->flags & BNA_ETHPORT_F_RX_STARTED) &&
- (ethport->flags & BNA_ETHPORT_F_PORT_ENABLED));
- else
- ready = ((ethport->flags & BNA_ETHPORT_F_ADMIN_UP) &&
- (ethport->flags & BNA_ETHPORT_F_RX_STARTED) &&
- !(ethport->flags & BNA_ETHPORT_F_PORT_ENABLED));
- return ready;
- }
- #define ethport_is_up ethport_can_be_up
- enum bna_ethport_event {
- ETHPORT_E_START = 1,
- ETHPORT_E_STOP = 2,
- ETHPORT_E_FAIL = 3,
- ETHPORT_E_UP = 4,
- ETHPORT_E_DOWN = 5,
- ETHPORT_E_FWRESP_UP_OK = 6,
- ETHPORT_E_FWRESP_DOWN = 7,
- ETHPORT_E_FWRESP_UP_FAIL = 8,
- };
- enum bna_enet_event {
- ENET_E_START = 1,
- ENET_E_STOP = 2,
- ENET_E_FAIL = 3,
- ENET_E_PAUSE_CFG = 4,
- ENET_E_MTU_CFG = 5,
- ENET_E_FWRESP_PAUSE = 6,
- ENET_E_CHLD_STOPPED = 7,
- };
- enum bna_ioceth_event {
- IOCETH_E_ENABLE = 1,
- IOCETH_E_DISABLE = 2,
- IOCETH_E_IOC_RESET = 3,
- IOCETH_E_IOC_FAILED = 4,
- IOCETH_E_IOC_READY = 5,
- IOCETH_E_ENET_ATTR_RESP = 6,
- IOCETH_E_ENET_STOPPED = 7,
- IOCETH_E_IOC_DISABLED = 8,
- };
- #define bna_stats_copy(_name, _type) \
- do { \
- count = sizeof(struct bfi_enet_stats_ ## _type) / sizeof(u64); \
- stats_src = (u64 *)&bna->stats.hw_stats_kva->_name ## _stats; \
- stats_dst = (u64 *)&bna->stats.hw_stats._name ## _stats; \
- for (i = 0; i < count; i++) \
- stats_dst[i] = be64_to_cpu(stats_src[i]); \
- } while (0) \
- /*
- * FW response handlers
- */
- static void
- bna_bfi_ethport_enable_aen(struct bna_ethport *ethport,
- struct bfi_msgq_mhdr *msghdr)
- {
- ethport->flags |= BNA_ETHPORT_F_PORT_ENABLED;
- if (ethport_can_be_up(ethport))
- bfa_fsm_send_event(ethport, ETHPORT_E_UP);
- }
- static void
- bna_bfi_ethport_disable_aen(struct bna_ethport *ethport,
- struct bfi_msgq_mhdr *msghdr)
- {
- int ethport_up = ethport_is_up(ethport);
- ethport->flags &= ~BNA_ETHPORT_F_PORT_ENABLED;
- if (ethport_up)
- bfa_fsm_send_event(ethport, ETHPORT_E_DOWN);
- }
- static void
- bna_bfi_ethport_admin_rsp(struct bna_ethport *ethport,
- struct bfi_msgq_mhdr *msghdr)
- {
- struct bfi_enet_enable_req *admin_req =
- ðport->bfi_enet_cmd.admin_req;
- struct bfi_enet_rsp *rsp = (struct bfi_enet_rsp *)msghdr;
- switch (admin_req->enable) {
- case BNA_STATUS_T_ENABLED:
- if (rsp->error == BFI_ENET_CMD_OK)
- bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_UP_OK);
- else {
- ethport->flags &= ~BNA_ETHPORT_F_PORT_ENABLED;
- bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_UP_FAIL);
- }
- break;
- case BNA_STATUS_T_DISABLED:
- bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_DOWN);
- ethport->link_status = BNA_LINK_DOWN;
- ethport->link_cbfn(ethport->bna->bnad, BNA_LINK_DOWN);
- break;
- }
- }
- static void
- bna_bfi_ethport_lpbk_rsp(struct bna_ethport *ethport,
- struct bfi_msgq_mhdr *msghdr)
- {
- struct bfi_enet_diag_lb_req *diag_lb_req =
- ðport->bfi_enet_cmd.lpbk_req;
- struct bfi_enet_rsp *rsp = (struct bfi_enet_rsp *)msghdr;
- switch (diag_lb_req->enable) {
- case BNA_STATUS_T_ENABLED:
- if (rsp->error == BFI_ENET_CMD_OK)
- bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_UP_OK);
- else {
- ethport->flags &= ~BNA_ETHPORT_F_ADMIN_UP;
- bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_UP_FAIL);
- }
- break;
- case BNA_STATUS_T_DISABLED:
- bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_DOWN);
- break;
- }
- }
- static void
- bna_bfi_pause_set_rsp(struct bna_enet *enet, struct bfi_msgq_mhdr *msghdr)
- {
- bfa_fsm_send_event(enet, ENET_E_FWRESP_PAUSE);
- }
- static void
- bna_bfi_attr_get_rsp(struct bna_ioceth *ioceth,
- struct bfi_msgq_mhdr *msghdr)
- {
- struct bfi_enet_attr_rsp *rsp = (struct bfi_enet_attr_rsp *)msghdr;
- /**
- * Store only if not set earlier, since BNAD can override the HW
- * attributes
- */
- if (!ioceth->attr.fw_query_complete) {
- ioceth->attr.num_txq = ntohl(rsp->max_cfg);
- ioceth->attr.num_rxp = ntohl(rsp->max_cfg);
- ioceth->attr.num_ucmac = ntohl(rsp->max_ucmac);
- ioceth->attr.num_mcmac = BFI_ENET_MAX_MCAM;
- ioceth->attr.max_rit_size = ntohl(rsp->rit_size);
- ioceth->attr.fw_query_complete = true;
- }
- bfa_fsm_send_event(ioceth, IOCETH_E_ENET_ATTR_RESP);
- }
- static void
- bna_bfi_stats_get_rsp(struct bna *bna, struct bfi_msgq_mhdr *msghdr)
- {
- struct bfi_enet_stats_req *stats_req = &bna->stats_mod.stats_get;
- u64 *stats_src;
- u64 *stats_dst;
- u32 tx_enet_mask = ntohl(stats_req->tx_enet_mask);
- u32 rx_enet_mask = ntohl(stats_req->rx_enet_mask);
- int count;
- int i;
- bna_stats_copy(mac, mac);
- bna_stats_copy(bpc, bpc);
- bna_stats_copy(rad, rad);
- bna_stats_copy(rlb, rad);
- bna_stats_copy(fc_rx, fc_rx);
- bna_stats_copy(fc_tx, fc_tx);
- stats_src = (u64 *)&(bna->stats.hw_stats_kva->rxf_stats[0]);
- /* Copy Rxf stats to SW area, scatter them while copying */
- for (i = 0; i < BFI_ENET_CFG_MAX; i++) {
- stats_dst = (u64 *)&(bna->stats.hw_stats.rxf_stats[i]);
- memset(stats_dst, 0, sizeof(struct bfi_enet_stats_rxf));
- if (rx_enet_mask & ((u32)(1 << i))) {
- int k;
- count = sizeof(struct bfi_enet_stats_rxf) /
- sizeof(u64);
- for (k = 0; k < count; k++) {
- stats_dst[k] = be64_to_cpu(*stats_src);
- stats_src++;
- }
- }
- }
- /* Copy Txf stats to SW area, scatter them while copying */
- for (i = 0; i < BFI_ENET_CFG_MAX; i++) {
- stats_dst = (u64 *)&(bna->stats.hw_stats.txf_stats[i]);
- memset(stats_dst, 0, sizeof(struct bfi_enet_stats_txf));
- if (tx_enet_mask & ((u32)(1 << i))) {
- int k;
- count = sizeof(struct bfi_enet_stats_txf) /
- sizeof(u64);
- for (k = 0; k < count; k++) {
- stats_dst[k] = be64_to_cpu(*stats_src);
- stats_src++;
- }
- }
- }
- bna->stats_mod.stats_get_busy = false;
- bnad_cb_stats_get(bna->bnad, BNA_CB_SUCCESS, &bna->stats);
- }
- static void
- bna_bfi_ethport_linkup_aen(struct bna_ethport *ethport,
- struct bfi_msgq_mhdr *msghdr)
- {
- ethport->link_status = BNA_LINK_UP;
- /* Dispatch events */
- ethport->link_cbfn(ethport->bna->bnad, ethport->link_status);
- }
- static void
- bna_bfi_ethport_linkdown_aen(struct bna_ethport *ethport,
- struct bfi_msgq_mhdr *msghdr)
- {
- ethport->link_status = BNA_LINK_DOWN;
- /* Dispatch events */
- ethport->link_cbfn(ethport->bna->bnad, BNA_LINK_DOWN);
- }
- static void
- bna_err_handler(struct bna *bna, u32 intr_status)
- {
- if (BNA_IS_HALT_INTR(bna, intr_status))
- bna_halt_clear(bna);
- bfa_nw_ioc_error_isr(&bna->ioceth.ioc);
- }
- void
- bna_mbox_handler(struct bna *bna, u32 intr_status)
- {
- if (BNA_IS_ERR_INTR(bna, intr_status)) {
- bna_err_handler(bna, intr_status);
- return;
- }
- if (BNA_IS_MBOX_INTR(bna, intr_status))
- bfa_nw_ioc_mbox_isr(&bna->ioceth.ioc);
- }
- static void
- bna_msgq_rsp_handler(void *arg, struct bfi_msgq_mhdr *msghdr)
- {
- struct bna *bna = (struct bna *)arg;
- struct bna_tx *tx;
- struct bna_rx *rx;
- switch (msghdr->msg_id) {
- case BFI_ENET_I2H_RX_CFG_SET_RSP:
- bna_rx_from_rid(bna, msghdr->enet_id, rx);
- if (rx)
- bna_bfi_rx_enet_start_rsp(rx, msghdr);
- break;
- case BFI_ENET_I2H_RX_CFG_CLR_RSP:
- bna_rx_from_rid(bna, msghdr->enet_id, rx);
- if (rx)
- bna_bfi_rx_enet_stop_rsp(rx, msghdr);
- break;
- case BFI_ENET_I2H_RIT_CFG_RSP:
- case BFI_ENET_I2H_RSS_CFG_RSP:
- case BFI_ENET_I2H_RSS_ENABLE_RSP:
- case BFI_ENET_I2H_RX_PROMISCUOUS_RSP:
- case BFI_ENET_I2H_RX_DEFAULT_RSP:
- case BFI_ENET_I2H_MAC_UCAST_SET_RSP:
- case BFI_ENET_I2H_MAC_UCAST_CLR_RSP:
- case BFI_ENET_I2H_MAC_UCAST_ADD_RSP:
- case BFI_ENET_I2H_MAC_UCAST_DEL_RSP:
- case BFI_ENET_I2H_MAC_MCAST_DEL_RSP:
- case BFI_ENET_I2H_MAC_MCAST_FILTER_RSP:
- case BFI_ENET_I2H_RX_VLAN_SET_RSP:
- case BFI_ENET_I2H_RX_VLAN_STRIP_ENABLE_RSP:
- bna_rx_from_rid(bna, msghdr->enet_id, rx);
- if (rx)
- bna_bfi_rxf_cfg_rsp(&rx->rxf, msghdr);
- break;
- case BFI_ENET_I2H_MAC_MCAST_ADD_RSP:
- bna_rx_from_rid(bna, msghdr->enet_id, rx);
- if (rx)
- bna_bfi_rxf_mcast_add_rsp(&rx->rxf, msghdr);
- break;
- case BFI_ENET_I2H_TX_CFG_SET_RSP:
- bna_tx_from_rid(bna, msghdr->enet_id, tx);
- if (tx)
- bna_bfi_tx_enet_start_rsp(tx, msghdr);
- break;
- case BFI_ENET_I2H_TX_CFG_CLR_RSP:
- bna_tx_from_rid(bna, msghdr->enet_id, tx);
- if (tx)
- bna_bfi_tx_enet_stop_rsp(tx, msghdr);
- break;
- case BFI_ENET_I2H_PORT_ADMIN_RSP:
- bna_bfi_ethport_admin_rsp(&bna->ethport, msghdr);
- break;
- case BFI_ENET_I2H_DIAG_LOOPBACK_RSP:
- bna_bfi_ethport_lpbk_rsp(&bna->ethport, msghdr);
- break;
- case BFI_ENET_I2H_SET_PAUSE_RSP:
- bna_bfi_pause_set_rsp(&bna->enet, msghdr);
- break;
- case BFI_ENET_I2H_GET_ATTR_RSP:
- bna_bfi_attr_get_rsp(&bna->ioceth, msghdr);
- break;
- case BFI_ENET_I2H_STATS_GET_RSP:
- bna_bfi_stats_get_rsp(bna, msghdr);
- break;
- case BFI_ENET_I2H_STATS_CLR_RSP:
- /* No-op */
- break;
- case BFI_ENET_I2H_LINK_UP_AEN:
- bna_bfi_ethport_linkup_aen(&bna->ethport, msghdr);
- break;
- case BFI_ENET_I2H_LINK_DOWN_AEN:
- bna_bfi_ethport_linkdown_aen(&bna->ethport, msghdr);
- break;
- case BFI_ENET_I2H_PORT_ENABLE_AEN:
- bna_bfi_ethport_enable_aen(&bna->ethport, msghdr);
- break;
- case BFI_ENET_I2H_PORT_DISABLE_AEN:
- bna_bfi_ethport_disable_aen(&bna->ethport, msghdr);
- break;
- case BFI_ENET_I2H_BW_UPDATE_AEN:
- bna_bfi_bw_update_aen(&bna->tx_mod);
- break;
- default:
- break;
- }
- }
- /**
- * ETHPORT
- */
- #define call_ethport_stop_cbfn(_ethport) \
- do { \
- if ((_ethport)->stop_cbfn) { \
- void (*cbfn)(struct bna_enet *); \
- cbfn = (_ethport)->stop_cbfn; \
- (_ethport)->stop_cbfn = NULL; \
- cbfn(&(_ethport)->bna->enet); \
- } \
- } while (0)
- #define call_ethport_adminup_cbfn(ethport, status) \
- do { \
- if ((ethport)->adminup_cbfn) { \
- void (*cbfn)(struct bnad *, enum bna_cb_status); \
- cbfn = (ethport)->adminup_cbfn; \
- (ethport)->adminup_cbfn = NULL; \
- cbfn((ethport)->bna->bnad, status); \
- } \
- } while (0)
- static void
- bna_bfi_ethport_admin_up(struct bna_ethport *ethport)
- {
- struct bfi_enet_enable_req *admin_up_req =
- ðport->bfi_enet_cmd.admin_req;
- bfi_msgq_mhdr_set(admin_up_req->mh, BFI_MC_ENET,
- BFI_ENET_H2I_PORT_ADMIN_UP_REQ, 0, 0);
- admin_up_req->mh.num_entries = htons(
- bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req)));
- admin_up_req->enable = BNA_STATUS_T_ENABLED;
- bfa_msgq_cmd_set(ðport->msgq_cmd, NULL, NULL,
- sizeof(struct bfi_enet_enable_req), &admin_up_req->mh);
- bfa_msgq_cmd_post(ðport->bna->msgq, ðport->msgq_cmd);
- }
- static void
- bna_bfi_ethport_admin_down(struct bna_ethport *ethport)
- {
- struct bfi_enet_enable_req *admin_down_req =
- ðport->bfi_enet_cmd.admin_req;
- bfi_msgq_mhdr_set(admin_down_req->mh, BFI_MC_ENET,
- BFI_ENET_H2I_PORT_ADMIN_UP_REQ, 0, 0);
- admin_down_req->mh.num_entries = htons(
- bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req)));
- admin_down_req->enable = BNA_STATUS_T_DISABLED;
- bfa_msgq_cmd_set(ðport->msgq_cmd, NULL, NULL,
- sizeof(struct bfi_enet_enable_req), &admin_down_req->mh);
- bfa_msgq_cmd_post(ðport->bna->msgq, ðport->msgq_cmd);
- }
- static void
- bna_bfi_ethport_lpbk_up(struct bna_ethport *ethport)
- {
- struct bfi_enet_diag_lb_req *lpbk_up_req =
- ðport->bfi_enet_cmd.lpbk_req;
- bfi_msgq_mhdr_set(lpbk_up_req->mh, BFI_MC_ENET,
- BFI_ENET_H2I_DIAG_LOOPBACK_REQ, 0, 0);
- lpbk_up_req->mh.num_entries = htons(
- bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_diag_lb_req)));
- lpbk_up_req->mode = (ethport->bna->enet.type ==
- BNA_ENET_T_LOOPBACK_INTERNAL) ?
- BFI_ENET_DIAG_LB_OPMODE_EXT :
- BFI_ENET_DIAG_LB_OPMODE_CBL;
- lpbk_up_req->enable = BNA_STATUS_T_ENABLED;
- bfa_msgq_cmd_set(ðport->msgq_cmd, NULL, NULL,
- sizeof(struct bfi_enet_diag_lb_req), &lpbk_up_req->mh);
- bfa_msgq_cmd_post(ðport->bna->msgq, ðport->msgq_cmd);
- }
- static void
- bna_bfi_ethport_lpbk_down(struct bna_ethport *ethport)
- {
- struct bfi_enet_diag_lb_req *lpbk_down_req =
- ðport->bfi_enet_cmd.lpbk_req;
- bfi_msgq_mhdr_set(lpbk_down_req->mh, BFI_MC_ENET,
- BFI_ENET_H2I_DIAG_LOOPBACK_REQ, 0, 0);
- lpbk_down_req->mh.num_entries = htons(
- bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_diag_lb_req)));
- lpbk_down_req->enable = BNA_STATUS_T_DISABLED;
- bfa_msgq_cmd_set(ðport->msgq_cmd, NULL, NULL,
- sizeof(struct bfi_enet_diag_lb_req), &lpbk_down_req->mh);
- bfa_msgq_cmd_post(ðport->bna->msgq, ðport->msgq_cmd);
- }
- static void
- bna_bfi_ethport_up(struct bna_ethport *ethport)
- {
- if (ethport->bna->enet.type == BNA_ENET_T_REGULAR)
- bna_bfi_ethport_admin_up(ethport);
- else
- bna_bfi_ethport_lpbk_up(ethport);
- }
- static void
- bna_bfi_ethport_down(struct bna_ethport *ethport)
- {
- if (ethport->bna->enet.type == BNA_ENET_T_REGULAR)
- bna_bfi_ethport_admin_down(ethport);
- else
- bna_bfi_ethport_lpbk_down(ethport);
- }
- bfa_fsm_state_decl(bna_ethport, stopped, struct bna_ethport,
- enum bna_ethport_event);
- bfa_fsm_state_decl(bna_ethport, down, struct bna_ethport,
- enum bna_ethport_event);
- bfa_fsm_state_decl(bna_ethport, up_resp_wait, struct bna_ethport,
- enum bna_ethport_event);
- bfa_fsm_state_decl(bna_ethport, down_resp_wait, struct bna_ethport,
- enum bna_ethport_event);
- bfa_fsm_state_decl(bna_ethport, up, struct bna_ethport,
- enum bna_ethport_event);
- bfa_fsm_state_decl(bna_ethport, last_resp_wait, struct bna_ethport,
- enum bna_ethport_event);
- static void
- bna_ethport_sm_stopped_entry(struct bna_ethport *ethport)
- {
- call_ethport_stop_cbfn(ethport);
- }
- static void
- bna_ethport_sm_stopped(struct bna_ethport *ethport,
- enum bna_ethport_event event)
- {
- switch (event) {
- case ETHPORT_E_START:
- bfa_fsm_set_state(ethport, bna_ethport_sm_down);
- break;
- case ETHPORT_E_STOP:
- call_ethport_stop_cbfn(ethport);
- break;
- case ETHPORT_E_FAIL:
- /* No-op */
- break;
- case ETHPORT_E_DOWN:
- /* This event is received due to Rx objects failing */
- /* No-op */
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ethport_sm_down_entry(struct bna_ethport *ethport)
- {
- }
- static void
- bna_ethport_sm_down(struct bna_ethport *ethport,
- enum bna_ethport_event event)
- {
- switch (event) {
- case ETHPORT_E_STOP:
- bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
- break;
- case ETHPORT_E_FAIL:
- bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
- break;
- case ETHPORT_E_UP:
- bfa_fsm_set_state(ethport, bna_ethport_sm_up_resp_wait);
- bna_bfi_ethport_up(ethport);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ethport_sm_up_resp_wait_entry(struct bna_ethport *ethport)
- {
- }
- static void
- bna_ethport_sm_up_resp_wait(struct bna_ethport *ethport,
- enum bna_ethport_event event)
- {
- switch (event) {
- case ETHPORT_E_STOP:
- bfa_fsm_set_state(ethport, bna_ethport_sm_last_resp_wait);
- break;
- case ETHPORT_E_FAIL:
- call_ethport_adminup_cbfn(ethport, BNA_CB_FAIL);
- bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
- break;
- case ETHPORT_E_DOWN:
- call_ethport_adminup_cbfn(ethport, BNA_CB_INTERRUPT);
- bfa_fsm_set_state(ethport, bna_ethport_sm_down_resp_wait);
- break;
- case ETHPORT_E_FWRESP_UP_OK:
- call_ethport_adminup_cbfn(ethport, BNA_CB_SUCCESS);
- bfa_fsm_set_state(ethport, bna_ethport_sm_up);
- break;
- case ETHPORT_E_FWRESP_UP_FAIL:
- call_ethport_adminup_cbfn(ethport, BNA_CB_FAIL);
- bfa_fsm_set_state(ethport, bna_ethport_sm_down);
- break;
- case ETHPORT_E_FWRESP_DOWN:
- /* down_resp_wait -> up_resp_wait transition on ETHPORT_E_UP */
- bna_bfi_ethport_up(ethport);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ethport_sm_down_resp_wait_entry(struct bna_ethport *ethport)
- {
- /**
- * NOTE: Do not call bna_bfi_ethport_down() here. That will over step
- * mbox due to up_resp_wait -> down_resp_wait transition on event
- * ETHPORT_E_DOWN
- */
- }
- static void
- bna_ethport_sm_down_resp_wait(struct bna_ethport *ethport,
- enum bna_ethport_event event)
- {
- switch (event) {
- case ETHPORT_E_STOP:
- bfa_fsm_set_state(ethport, bna_ethport_sm_last_resp_wait);
- break;
- case ETHPORT_E_FAIL:
- bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
- break;
- case ETHPORT_E_UP:
- bfa_fsm_set_state(ethport, bna_ethport_sm_up_resp_wait);
- break;
- case ETHPORT_E_FWRESP_UP_OK:
- /* up_resp_wait->down_resp_wait transition on ETHPORT_E_DOWN */
- bna_bfi_ethport_down(ethport);
- break;
- case ETHPORT_E_FWRESP_UP_FAIL:
- case ETHPORT_E_FWRESP_DOWN:
- bfa_fsm_set_state(ethport, bna_ethport_sm_down);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ethport_sm_up_entry(struct bna_ethport *ethport)
- {
- }
- static void
- bna_ethport_sm_up(struct bna_ethport *ethport,
- enum bna_ethport_event event)
- {
- switch (event) {
- case ETHPORT_E_STOP:
- bfa_fsm_set_state(ethport, bna_ethport_sm_last_resp_wait);
- bna_bfi_ethport_down(ethport);
- break;
- case ETHPORT_E_FAIL:
- bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
- break;
- case ETHPORT_E_DOWN:
- bfa_fsm_set_state(ethport, bna_ethport_sm_down_resp_wait);
- bna_bfi_ethport_down(ethport);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ethport_sm_last_resp_wait_entry(struct bna_ethport *ethport)
- {
- }
- static void
- bna_ethport_sm_last_resp_wait(struct bna_ethport *ethport,
- enum bna_ethport_event event)
- {
- switch (event) {
- case ETHPORT_E_FAIL:
- bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
- break;
- case ETHPORT_E_DOWN:
- /**
- * This event is received due to Rx objects stopping in
- * parallel to ethport
- */
- /* No-op */
- break;
- case ETHPORT_E_FWRESP_UP_OK:
- /* up_resp_wait->last_resp_wait transition on ETHPORT_T_STOP */
- bna_bfi_ethport_down(ethport);
- break;
- case ETHPORT_E_FWRESP_UP_FAIL:
- case ETHPORT_E_FWRESP_DOWN:
- bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ethport_init(struct bna_ethport *ethport, struct bna *bna)
- {
- ethport->flags |= (BNA_ETHPORT_F_ADMIN_UP | BNA_ETHPORT_F_PORT_ENABLED);
- ethport->bna = bna;
- ethport->link_status = BNA_LINK_DOWN;
- ethport->link_cbfn = bnad_cb_ethport_link_status;
- ethport->rx_started_count = 0;
- ethport->stop_cbfn = NULL;
- ethport->adminup_cbfn = NULL;
- bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
- }
- static void
- bna_ethport_uninit(struct bna_ethport *ethport)
- {
- ethport->flags &= ~BNA_ETHPORT_F_ADMIN_UP;
- ethport->flags &= ~BNA_ETHPORT_F_PORT_ENABLED;
- ethport->bna = NULL;
- }
- static void
- bna_ethport_start(struct bna_ethport *ethport)
- {
- bfa_fsm_send_event(ethport, ETHPORT_E_START);
- }
- static void
- bna_enet_cb_ethport_stopped(struct bna_enet *enet)
- {
- bfa_wc_down(&enet->chld_stop_wc);
- }
- static void
- bna_ethport_stop(struct bna_ethport *ethport)
- {
- ethport->stop_cbfn = bna_enet_cb_ethport_stopped;
- bfa_fsm_send_event(ethport, ETHPORT_E_STOP);
- }
- static void
- bna_ethport_fail(struct bna_ethport *ethport)
- {
- /* Reset the physical port status to enabled */
- ethport->flags |= BNA_ETHPORT_F_PORT_ENABLED;
- if (ethport->link_status != BNA_LINK_DOWN) {
- ethport->link_status = BNA_LINK_DOWN;
- ethport->link_cbfn(ethport->bna->bnad, BNA_LINK_DOWN);
- }
- bfa_fsm_send_event(ethport, ETHPORT_E_FAIL);
- }
- /* Should be called only when ethport is disabled */
- void
- bna_ethport_cb_rx_started(struct bna_ethport *ethport)
- {
- ethport->rx_started_count++;
- if (ethport->rx_started_count == 1) {
- ethport->flags |= BNA_ETHPORT_F_RX_STARTED;
- if (ethport_can_be_up(ethport))
- bfa_fsm_send_event(ethport, ETHPORT_E_UP);
- }
- }
- void
- bna_ethport_cb_rx_stopped(struct bna_ethport *ethport)
- {
- int ethport_up = ethport_is_up(ethport);
- ethport->rx_started_count--;
- if (ethport->rx_started_count == 0) {
- ethport->flags &= ~BNA_ETHPORT_F_RX_STARTED;
- if (ethport_up)
- bfa_fsm_send_event(ethport, ETHPORT_E_DOWN);
- }
- }
- /**
- * ENET
- */
- #define bna_enet_chld_start(enet) \
- do { \
- enum bna_tx_type tx_type = \
- ((enet)->type == BNA_ENET_T_REGULAR) ? \
- BNA_TX_T_REGULAR : BNA_TX_T_LOOPBACK; \
- enum bna_rx_type rx_type = \
- ((enet)->type == BNA_ENET_T_REGULAR) ? \
- BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK; \
- bna_ethport_start(&(enet)->bna->ethport); \
- bna_tx_mod_start(&(enet)->bna->tx_mod, tx_type); \
- bna_rx_mod_start(&(enet)->bna->rx_mod, rx_type); \
- } while (0)
- #define bna_enet_chld_stop(enet) \
- do { \
- enum bna_tx_type tx_type = \
- ((enet)->type == BNA_ENET_T_REGULAR) ? \
- BNA_TX_T_REGULAR : BNA_TX_T_LOOPBACK; \
- enum bna_rx_type rx_type = \
- ((enet)->type == BNA_ENET_T_REGULAR) ? \
- BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK; \
- bfa_wc_init(&(enet)->chld_stop_wc, bna_enet_cb_chld_stopped, (enet));\
- bfa_wc_up(&(enet)->chld_stop_wc); \
- bna_ethport_stop(&(enet)->bna->ethport); \
- bfa_wc_up(&(enet)->chld_stop_wc); \
- bna_tx_mod_stop(&(enet)->bna->tx_mod, tx_type); \
- bfa_wc_up(&(enet)->chld_stop_wc); \
- bna_rx_mod_stop(&(enet)->bna->rx_mod, rx_type); \
- bfa_wc_wait(&(enet)->chld_stop_wc); \
- } while (0)
- #define bna_enet_chld_fail(enet) \
- do { \
- bna_ethport_fail(&(enet)->bna->ethport); \
- bna_tx_mod_fail(&(enet)->bna->tx_mod); \
- bna_rx_mod_fail(&(enet)->bna->rx_mod); \
- } while (0)
- #define bna_enet_rx_start(enet) \
- do { \
- enum bna_rx_type rx_type = \
- ((enet)->type == BNA_ENET_T_REGULAR) ? \
- BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK; \
- bna_rx_mod_start(&(enet)->bna->rx_mod, rx_type); \
- } while (0)
- #define bna_enet_rx_stop(enet) \
- do { \
- enum bna_rx_type rx_type = \
- ((enet)->type == BNA_ENET_T_REGULAR) ? \
- BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK; \
- bfa_wc_init(&(enet)->chld_stop_wc, bna_enet_cb_chld_stopped, (enet));\
- bfa_wc_up(&(enet)->chld_stop_wc); \
- bna_rx_mod_stop(&(enet)->bna->rx_mod, rx_type); \
- bfa_wc_wait(&(enet)->chld_stop_wc); \
- } while (0)
- #define call_enet_stop_cbfn(enet) \
- do { \
- if ((enet)->stop_cbfn) { \
- void (*cbfn)(void *); \
- void *cbarg; \
- cbfn = (enet)->stop_cbfn; \
- cbarg = (enet)->stop_cbarg; \
- (enet)->stop_cbfn = NULL; \
- (enet)->stop_cbarg = NULL; \
- cbfn(cbarg); \
- } \
- } while (0)
- #define call_enet_pause_cbfn(enet) \
- do { \
- if ((enet)->pause_cbfn) { \
- void (*cbfn)(struct bnad *); \
- cbfn = (enet)->pause_cbfn; \
- (enet)->pause_cbfn = NULL; \
- cbfn((enet)->bna->bnad); \
- } \
- } while (0)
- #define call_enet_mtu_cbfn(enet) \
- do { \
- if ((enet)->mtu_cbfn) { \
- void (*cbfn)(struct bnad *); \
- cbfn = (enet)->mtu_cbfn; \
- (enet)->mtu_cbfn = NULL; \
- cbfn((enet)->bna->bnad); \
- } \
- } while (0)
- static void bna_enet_cb_chld_stopped(void *arg);
- static void bna_bfi_pause_set(struct bna_enet *enet);
- bfa_fsm_state_decl(bna_enet, stopped, struct bna_enet,
- enum bna_enet_event);
- bfa_fsm_state_decl(bna_enet, pause_init_wait, struct bna_enet,
- enum bna_enet_event);
- bfa_fsm_state_decl(bna_enet, last_resp_wait, struct bna_enet,
- enum bna_enet_event);
- bfa_fsm_state_decl(bna_enet, started, struct bna_enet,
- enum bna_enet_event);
- bfa_fsm_state_decl(bna_enet, cfg_wait, struct bna_enet,
- enum bna_enet_event);
- bfa_fsm_state_decl(bna_enet, cfg_stop_wait, struct bna_enet,
- enum bna_enet_event);
- bfa_fsm_state_decl(bna_enet, chld_stop_wait, struct bna_enet,
- enum bna_enet_event);
- static void
- bna_enet_sm_stopped_entry(struct bna_enet *enet)
- {
- call_enet_pause_cbfn(enet);
- call_enet_mtu_cbfn(enet);
- call_enet_stop_cbfn(enet);
- }
- static void
- bna_enet_sm_stopped(struct bna_enet *enet, enum bna_enet_event event)
- {
- switch (event) {
- case ENET_E_START:
- bfa_fsm_set_state(enet, bna_enet_sm_pause_init_wait);
- break;
- case ENET_E_STOP:
- call_enet_stop_cbfn(enet);
- break;
- case ENET_E_FAIL:
- /* No-op */
- break;
- case ENET_E_PAUSE_CFG:
- call_enet_pause_cbfn(enet);
- break;
- case ENET_E_MTU_CFG:
- call_enet_mtu_cbfn(enet);
- break;
- case ENET_E_CHLD_STOPPED:
- /**
- * This event is received due to Ethport, Tx and Rx objects
- * failing
- */
- /* No-op */
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_enet_sm_pause_init_wait_entry(struct bna_enet *enet)
- {
- bna_bfi_pause_set(enet);
- }
- static void
- bna_enet_sm_pause_init_wait(struct bna_enet *enet,
- enum bna_enet_event event)
- {
- switch (event) {
- case ENET_E_STOP:
- enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
- bfa_fsm_set_state(enet, bna_enet_sm_last_resp_wait);
- break;
- case ENET_E_FAIL:
- enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
- bfa_fsm_set_state(enet, bna_enet_sm_stopped);
- break;
- case ENET_E_PAUSE_CFG:
- enet->flags |= BNA_ENET_F_PAUSE_CHANGED;
- break;
- case ENET_E_MTU_CFG:
- /* No-op */
- break;
- case ENET_E_FWRESP_PAUSE:
- if (enet->flags & BNA_ENET_F_PAUSE_CHANGED) {
- enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
- bna_bfi_pause_set(enet);
- } else {
- bfa_fsm_set_state(enet, bna_enet_sm_started);
- bna_enet_chld_start(enet);
- }
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_enet_sm_last_resp_wait_entry(struct bna_enet *enet)
- {
- enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
- }
- static void
- bna_enet_sm_last_resp_wait(struct bna_enet *enet,
- enum bna_enet_event event)
- {
- switch (event) {
- case ENET_E_FAIL:
- case ENET_E_FWRESP_PAUSE:
- bfa_fsm_set_state(enet, bna_enet_sm_stopped);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_enet_sm_started_entry(struct bna_enet *enet)
- {
- /**
- * NOTE: Do not call bna_enet_chld_start() here, since it will be
- * inadvertently called during cfg_wait->started transition as well
- */
- call_enet_pause_cbfn(enet);
- call_enet_mtu_cbfn(enet);
- }
- static void
- bna_enet_sm_started(struct bna_enet *enet,
- enum bna_enet_event event)
- {
- switch (event) {
- case ENET_E_STOP:
- bfa_fsm_set_state(enet, bna_enet_sm_chld_stop_wait);
- break;
- case ENET_E_FAIL:
- bfa_fsm_set_state(enet, bna_enet_sm_stopped);
- bna_enet_chld_fail(enet);
- break;
- case ENET_E_PAUSE_CFG:
- bfa_fsm_set_state(enet, bna_enet_sm_cfg_wait);
- bna_bfi_pause_set(enet);
- break;
- case ENET_E_MTU_CFG:
- bfa_fsm_set_state(enet, bna_enet_sm_cfg_wait);
- bna_enet_rx_stop(enet);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_enet_sm_cfg_wait_entry(struct bna_enet *enet)
- {
- }
- static void
- bna_enet_sm_cfg_wait(struct bna_enet *enet,
- enum bna_enet_event event)
- {
- switch (event) {
- case ENET_E_STOP:
- enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
- enet->flags &= ~BNA_ENET_F_MTU_CHANGED;
- bfa_fsm_set_state(enet, bna_enet_sm_cfg_stop_wait);
- break;
- case ENET_E_FAIL:
- enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
- enet->flags &= ~BNA_ENET_F_MTU_CHANGED;
- bfa_fsm_set_state(enet, bna_enet_sm_stopped);
- bna_enet_chld_fail(enet);
- break;
- case ENET_E_PAUSE_CFG:
- enet->flags |= BNA_ENET_F_PAUSE_CHANGED;
- break;
- case ENET_E_MTU_CFG:
- enet->flags |= BNA_ENET_F_MTU_CHANGED;
- break;
- case ENET_E_CHLD_STOPPED:
- bna_enet_rx_start(enet);
- /* Fall through */
- case ENET_E_FWRESP_PAUSE:
- if (enet->flags & BNA_ENET_F_PAUSE_CHANGED) {
- enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
- bna_bfi_pause_set(enet);
- } else if (enet->flags & BNA_ENET_F_MTU_CHANGED) {
- enet->flags &= ~BNA_ENET_F_MTU_CHANGED;
- bna_enet_rx_stop(enet);
- } else {
- bfa_fsm_set_state(enet, bna_enet_sm_started);
- }
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_enet_sm_cfg_stop_wait_entry(struct bna_enet *enet)
- {
- enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
- enet->flags &= ~BNA_ENET_F_MTU_CHANGED;
- }
- static void
- bna_enet_sm_cfg_stop_wait(struct bna_enet *enet,
- enum bna_enet_event event)
- {
- switch (event) {
- case ENET_E_FAIL:
- bfa_fsm_set_state(enet, bna_enet_sm_stopped);
- bna_enet_chld_fail(enet);
- break;
- case ENET_E_FWRESP_PAUSE:
- case ENET_E_CHLD_STOPPED:
- bfa_fsm_set_state(enet, bna_enet_sm_chld_stop_wait);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_enet_sm_chld_stop_wait_entry(struct bna_enet *enet)
- {
- bna_enet_chld_stop(enet);
- }
- static void
- bna_enet_sm_chld_stop_wait(struct bna_enet *enet,
- enum bna_enet_event event)
- {
- switch (event) {
- case ENET_E_FAIL:
- bfa_fsm_set_state(enet, bna_enet_sm_stopped);
- bna_enet_chld_fail(enet);
- break;
- case ENET_E_CHLD_STOPPED:
- bfa_fsm_set_state(enet, bna_enet_sm_stopped);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_bfi_pause_set(struct bna_enet *enet)
- {
- struct bfi_enet_set_pause_req *pause_req = &enet->pause_req;
- bfi_msgq_mhdr_set(pause_req->mh, BFI_MC_ENET,
- BFI_ENET_H2I_SET_PAUSE_REQ, 0, 0);
- pause_req->mh.num_entries = htons(
- bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_set_pause_req)));
- pause_req->tx_pause = enet->pause_config.tx_pause;
- pause_req->rx_pause = enet->pause_config.rx_pause;
- bfa_msgq_cmd_set(&enet->msgq_cmd, NULL, NULL,
- sizeof(struct bfi_enet_set_pause_req), &pause_req->mh);
- bfa_msgq_cmd_post(&enet->bna->msgq, &enet->msgq_cmd);
- }
- static void
- bna_enet_cb_chld_stopped(void *arg)
- {
- struct bna_enet *enet = (struct bna_enet *)arg;
- bfa_fsm_send_event(enet, ENET_E_CHLD_STOPPED);
- }
- static void
- bna_enet_init(struct bna_enet *enet, struct bna *bna)
- {
- enet->bna = bna;
- enet->flags = 0;
- enet->mtu = 0;
- enet->type = BNA_ENET_T_REGULAR;
- enet->stop_cbfn = NULL;
- enet->stop_cbarg = NULL;
- enet->pause_cbfn = NULL;
- enet->mtu_cbfn = NULL;
- bfa_fsm_set_state(enet, bna_enet_sm_stopped);
- }
- static void
- bna_enet_uninit(struct bna_enet *enet)
- {
- enet->flags = 0;
- enet->bna = NULL;
- }
- static void
- bna_enet_start(struct bna_enet *enet)
- {
- enet->flags |= BNA_ENET_F_IOCETH_READY;
- if (enet->flags & BNA_ENET_F_ENABLED)
- bfa_fsm_send_event(enet, ENET_E_START);
- }
- static void
- bna_ioceth_cb_enet_stopped(void *arg)
- {
- struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
- bfa_fsm_send_event(ioceth, IOCETH_E_ENET_STOPPED);
- }
- static void
- bna_enet_stop(struct bna_enet *enet)
- {
- enet->stop_cbfn = bna_ioceth_cb_enet_stopped;
- enet->stop_cbarg = &enet->bna->ioceth;
- enet->flags &= ~BNA_ENET_F_IOCETH_READY;
- bfa_fsm_send_event(enet, ENET_E_STOP);
- }
- static void
- bna_enet_fail(struct bna_enet *enet)
- {
- enet->flags &= ~BNA_ENET_F_IOCETH_READY;
- bfa_fsm_send_event(enet, ENET_E_FAIL);
- }
- void
- bna_enet_cb_tx_stopped(struct bna_enet *enet)
- {
- bfa_wc_down(&enet->chld_stop_wc);
- }
- void
- bna_enet_cb_rx_stopped(struct bna_enet *enet)
- {
- bfa_wc_down(&enet->chld_stop_wc);
- }
- int
- bna_enet_mtu_get(struct bna_enet *enet)
- {
- return enet->mtu;
- }
- void
- bna_enet_enable(struct bna_enet *enet)
- {
- if (enet->fsm != (bfa_sm_t)bna_enet_sm_stopped)
- return;
- enet->flags |= BNA_ENET_F_ENABLED;
- if (enet->flags & BNA_ENET_F_IOCETH_READY)
- bfa_fsm_send_event(enet, ENET_E_START);
- }
- void
- bna_enet_disable(struct bna_enet *enet, enum bna_cleanup_type type,
- void (*cbfn)(void *))
- {
- if (type == BNA_SOFT_CLEANUP) {
- (*cbfn)(enet->bna->bnad);
- return;
- }
- enet->stop_cbfn = cbfn;
- enet->stop_cbarg = enet->bna->bnad;
- enet->flags &= ~BNA_ENET_F_ENABLED;
- bfa_fsm_send_event(enet, ENET_E_STOP);
- }
- void
- bna_enet_pause_config(struct bna_enet *enet,
- struct bna_pause_config *pause_config,
- void (*cbfn)(struct bnad *))
- {
- enet->pause_config = *pause_config;
- enet->pause_cbfn = cbfn;
- bfa_fsm_send_event(enet, ENET_E_PAUSE_CFG);
- }
- void
- bna_enet_mtu_set(struct bna_enet *enet, int mtu,
- void (*cbfn)(struct bnad *))
- {
- enet->mtu = mtu;
- enet->mtu_cbfn = cbfn;
- bfa_fsm_send_event(enet, ENET_E_MTU_CFG);
- }
- void
- bna_enet_perm_mac_get(struct bna_enet *enet, mac_t *mac)
- {
- *mac = bfa_nw_ioc_get_mac(&enet->bna->ioceth.ioc);
- }
- /**
- * IOCETH
- */
- #define enable_mbox_intr(_ioceth) \
- do { \
- u32 intr_status; \
- bna_intr_status_get((_ioceth)->bna, intr_status); \
- bnad_cb_mbox_intr_enable((_ioceth)->bna->bnad); \
- bna_mbox_intr_enable((_ioceth)->bna); \
- } while (0)
- #define disable_mbox_intr(_ioceth) \
- do { \
- bna_mbox_intr_disable((_ioceth)->bna); \
- bnad_cb_mbox_intr_disable((_ioceth)->bna->bnad); \
- } while (0)
- #define call_ioceth_stop_cbfn(_ioceth) \
- do { \
- if ((_ioceth)->stop_cbfn) { \
- void (*cbfn)(struct bnad *); \
- struct bnad *cbarg; \
- cbfn = (_ioceth)->stop_cbfn; \
- cbarg = (_ioceth)->stop_cbarg; \
- (_ioceth)->stop_cbfn = NULL; \
- (_ioceth)->stop_cbarg = NULL; \
- cbfn(cbarg); \
- } \
- } while (0)
- #define bna_stats_mod_uninit(_stats_mod) \
- do { \
- } while (0)
- #define bna_stats_mod_start(_stats_mod) \
- do { \
- (_stats_mod)->ioc_ready = true; \
- } while (0)
- #define bna_stats_mod_stop(_stats_mod) \
- do { \
- (_stats_mod)->ioc_ready = false; \
- } while (0)
- #define bna_stats_mod_fail(_stats_mod) \
- do { \
- (_stats_mod)->ioc_ready = false; \
- (_stats_mod)->stats_get_busy = false; \
- (_stats_mod)->stats_clr_busy = false; \
- } while (0)
- static void bna_bfi_attr_get(struct bna_ioceth *ioceth);
- bfa_fsm_state_decl(bna_ioceth, stopped, struct bna_ioceth,
- enum bna_ioceth_event);
- bfa_fsm_state_decl(bna_ioceth, ioc_ready_wait, struct bna_ioceth,
- enum bna_ioceth_event);
- bfa_fsm_state_decl(bna_ioceth, enet_attr_wait, struct bna_ioceth,
- enum bna_ioceth_event);
- bfa_fsm_state_decl(bna_ioceth, ready, struct bna_ioceth,
- enum bna_ioceth_event);
- bfa_fsm_state_decl(bna_ioceth, last_resp_wait, struct bna_ioceth,
- enum bna_ioceth_event);
- bfa_fsm_state_decl(bna_ioceth, enet_stop_wait, struct bna_ioceth,
- enum bna_ioceth_event);
- bfa_fsm_state_decl(bna_ioceth, ioc_disable_wait, struct bna_ioceth,
- enum bna_ioceth_event);
- bfa_fsm_state_decl(bna_ioceth, failed, struct bna_ioceth,
- enum bna_ioceth_event);
- static void
- bna_ioceth_sm_stopped_entry(struct bna_ioceth *ioceth)
- {
- call_ioceth_stop_cbfn(ioceth);
- }
- static void
- bna_ioceth_sm_stopped(struct bna_ioceth *ioceth,
- enum bna_ioceth_event event)
- {
- switch (event) {
- case IOCETH_E_ENABLE:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_ready_wait);
- bfa_nw_ioc_enable(&ioceth->ioc);
- break;
- case IOCETH_E_DISABLE:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_stopped);
- break;
- case IOCETH_E_IOC_RESET:
- enable_mbox_intr(ioceth);
- break;
- case IOCETH_E_IOC_FAILED:
- disable_mbox_intr(ioceth);
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_failed);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ioceth_sm_ioc_ready_wait_entry(struct bna_ioceth *ioceth)
- {
- /**
- * Do not call bfa_nw_ioc_enable() here. It must be called in the
- * previous state due to failed -> ioc_ready_wait transition.
- */
- }
- static void
- bna_ioceth_sm_ioc_ready_wait(struct bna_ioceth *ioceth,
- enum bna_ioceth_event event)
- {
- switch (event) {
- case IOCETH_E_DISABLE:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
- bfa_nw_ioc_disable(&ioceth->ioc);
- break;
- case IOCETH_E_IOC_RESET:
- enable_mbox_intr(ioceth);
- break;
- case IOCETH_E_IOC_FAILED:
- disable_mbox_intr(ioceth);
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_failed);
- break;
- case IOCETH_E_IOC_READY:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_enet_attr_wait);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ioceth_sm_enet_attr_wait_entry(struct bna_ioceth *ioceth)
- {
- bna_bfi_attr_get(ioceth);
- }
- static void
- bna_ioceth_sm_enet_attr_wait(struct bna_ioceth *ioceth,
- enum bna_ioceth_event event)
- {
- switch (event) {
- case IOCETH_E_DISABLE:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_last_resp_wait);
- break;
- case IOCETH_E_IOC_FAILED:
- disable_mbox_intr(ioceth);
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_failed);
- break;
- case IOCETH_E_ENET_ATTR_RESP:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_ready);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ioceth_sm_ready_entry(struct bna_ioceth *ioceth)
- {
- bna_enet_start(&ioceth->bna->enet);
- bna_stats_mod_start(&ioceth->bna->stats_mod);
- bnad_cb_ioceth_ready(ioceth->bna->bnad);
- }
- static void
- bna_ioceth_sm_ready(struct bna_ioceth *ioceth, enum bna_ioceth_event event)
- {
- switch (event) {
- case IOCETH_E_DISABLE:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_enet_stop_wait);
- break;
- case IOCETH_E_IOC_FAILED:
- disable_mbox_intr(ioceth);
- bna_enet_fail(&ioceth->bna->enet);
- bna_stats_mod_fail(&ioceth->bna->stats_mod);
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_failed);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ioceth_sm_last_resp_wait_entry(struct bna_ioceth *ioceth)
- {
- }
- static void
- bna_ioceth_sm_last_resp_wait(struct bna_ioceth *ioceth,
- enum bna_ioceth_event event)
- {
- switch (event) {
- case IOCETH_E_IOC_FAILED:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
- disable_mbox_intr(ioceth);
- bfa_nw_ioc_disable(&ioceth->ioc);
- break;
- case IOCETH_E_ENET_ATTR_RESP:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
- bfa_nw_ioc_disable(&ioceth->ioc);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ioceth_sm_enet_stop_wait_entry(struct bna_ioceth *ioceth)
- {
- bna_stats_mod_stop(&ioceth->bna->stats_mod);
- bna_enet_stop(&ioceth->bna->enet);
- }
- static void
- bna_ioceth_sm_enet_stop_wait(struct bna_ioceth *ioceth,
- enum bna_ioceth_event event)
- {
- switch (event) {
- case IOCETH_E_IOC_FAILED:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
- disable_mbox_intr(ioceth);
- bna_enet_fail(&ioceth->bna->enet);
- bna_stats_mod_fail(&ioceth->bna->stats_mod);
- bfa_nw_ioc_disable(&ioceth->ioc);
- break;
- case IOCETH_E_ENET_STOPPED:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
- bfa_nw_ioc_disable(&ioceth->ioc);
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ioceth_sm_ioc_disable_wait_entry(struct bna_ioceth *ioceth)
- {
- }
- static void
- bna_ioceth_sm_ioc_disable_wait(struct bna_ioceth *ioceth,
- enum bna_ioceth_event event)
- {
- switch (event) {
- case IOCETH_E_IOC_DISABLED:
- disable_mbox_intr(ioceth);
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_stopped);
- break;
- case IOCETH_E_ENET_STOPPED:
- /* This event is received due to enet failing */
- /* No-op */
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_ioceth_sm_failed_entry(struct bna_ioceth *ioceth)
- {
- bnad_cb_ioceth_failed(ioceth->bna->bnad);
- }
- static void
- bna_ioceth_sm_failed(struct bna_ioceth *ioceth,
- enum bna_ioceth_event event)
- {
- switch (event) {
- case IOCETH_E_DISABLE:
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
- bfa_nw_ioc_disable(&ioceth->ioc);
- break;
- case IOCETH_E_IOC_RESET:
- enable_mbox_intr(ioceth);
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_ready_wait);
- break;
- case IOCETH_E_IOC_FAILED:
- break;
- default:
- bfa_sm_fault(event);
- }
- }
- static void
- bna_bfi_attr_get(struct bna_ioceth *ioceth)
- {
- struct bfi_enet_attr_req *attr_req = &ioceth->attr_req;
- bfi_msgq_mhdr_set(attr_req->mh, BFI_MC_ENET,
- BFI_ENET_H2I_GET_ATTR_REQ, 0, 0);
- attr_req->mh.num_entries = htons(
- bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_attr_req)));
- bfa_msgq_cmd_set(&ioceth->msgq_cmd, NULL, NULL,
- sizeof(struct bfi_enet_attr_req), &attr_req->mh);
- bfa_msgq_cmd_post(&ioceth->bna->msgq, &ioceth->msgq_cmd);
- }
- /* IOC callback functions */
- static void
- bna_cb_ioceth_enable(void *arg, enum bfa_status error)
- {
- struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
- if (error)
- bfa_fsm_send_event(ioceth, IOCETH_E_IOC_FAILED);
- else
- bfa_fsm_send_event(ioceth, IOCETH_E_IOC_READY);
- }
- static void
- bna_cb_ioceth_disable(void *arg)
- {
- struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
- bfa_fsm_send_event(ioceth, IOCETH_E_IOC_DISABLED);
- }
- static void
- bna_cb_ioceth_hbfail(void *arg)
- {
- struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
- bfa_fsm_send_event(ioceth, IOCETH_E_IOC_FAILED);
- }
- static void
- bna_cb_ioceth_reset(void *arg)
- {
- struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
- bfa_fsm_send_event(ioceth, IOCETH_E_IOC_RESET);
- }
- static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
- bna_cb_ioceth_enable,
- bna_cb_ioceth_disable,
- bna_cb_ioceth_hbfail,
- bna_cb_ioceth_reset
- };
- static void bna_attr_init(struct bna_ioceth *ioceth)
- {
- ioceth->attr.num_txq = BFI_ENET_DEF_TXQ;
- ioceth->attr.num_rxp = BFI_ENET_DEF_RXP;
- ioceth->attr.num_ucmac = BFI_ENET_DEF_UCAM;
- ioceth->attr.num_mcmac = BFI_ENET_MAX_MCAM;
- ioceth->attr.max_rit_size = BFI_ENET_DEF_RITSZ;
- ioceth->attr.fw_query_complete = false;
- }
- static void
- bna_ioceth_init(struct bna_ioceth *ioceth, struct bna *bna,
- struct bna_res_info *res_info)
- {
- u64 dma;
- u8 *kva;
- ioceth->bna = bna;
- /**
- * Attach IOC and claim:
- * 1. DMA memory for IOC attributes
- * 2. Kernel memory for FW trace
- */
- bfa_nw_ioc_attach(&ioceth->ioc, ioceth, &bna_ioceth_cbfn);
- bfa_nw_ioc_pci_init(&ioceth->ioc, &bna->pcidev, BFI_PCIFN_CLASS_ETH);
- BNA_GET_DMA_ADDR(
- &res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.mdl[0].dma, dma);
- kva = res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.mdl[0].kva;
- bfa_nw_ioc_mem_claim(&ioceth->ioc, kva, dma);
- kva = res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.mdl[0].kva;
- /**
- * Attach common modules (Diag, SFP, CEE, Port) and claim respective
- * DMA memory.
- */
- BNA_GET_DMA_ADDR(
- &res_info[BNA_RES_MEM_T_COM].res_u.mem_info.mdl[0].dma, dma);
- kva = res_info[BNA_RES_MEM_T_COM].res_u.mem_info.mdl[0].kva;
- bfa_nw_cee_attach(&bna->cee, &ioceth->ioc, bna);
- bfa_nw_cee_mem_claim(&bna->cee, kva, dma);
- kva += bfa_nw_cee_meminfo();
- dma += bfa_nw_cee_meminfo();
- bfa_msgq_attach(&bna->msgq, &ioceth->ioc);
- bfa_msgq_memclaim(&bna->msgq, kva, dma);
- bfa_msgq_regisr(&bna->msgq, BFI_MC_ENET, bna_msgq_rsp_handler, bna);
- kva += bfa_msgq_meminfo();
- dma += bfa_msgq_meminfo();
- ioceth->stop_cbfn = NULL;
- ioceth->stop_cbarg = NULL;
- bna_attr_init(ioceth);
- bfa_fsm_set_state(ioceth, bna_ioceth_sm_stopped);
- }
- static void
- bna_ioceth_uninit(struct bna_ioceth *ioceth)
- {
- bfa_nw_ioc_detach(&ioceth->ioc);
- ioceth->bna = NULL;
- }
- void
- bna_ioceth_enable(struct bna_ioceth *ioceth)
- {
- if (ioceth->fsm == (bfa_fsm_t)bna_ioceth_sm_ready) {
- bnad_cb_ioceth_ready(ioceth->bna->bnad);
- return;
- }
- if (ioceth->fsm == (bfa_fsm_t)bna_ioceth_sm_stopped)
- bfa_fsm_send_event(ioceth, IOCETH_E_ENABLE);
- }
- void
- bna_ioceth_disable(struct bna_ioceth *ioceth, enum bna_cleanup_type type)
- {
- if (type == BNA_SOFT_CLEANUP) {
- bnad_cb_ioceth_disabled(ioceth->bna->bnad);
- return;
- }
- ioceth->stop_cbfn = bnad_cb_ioceth_disabled;
- ioceth->stop_cbarg = ioceth->bna->bnad;
- bfa_fsm_send_event(ioceth, IOCETH_E_DISABLE);
- }
- static void
- bna_ucam_mod_init(struct bna_ucam_mod *ucam_mod, struct bna *bna,
- struct bna_res_info *res_info)
- {
- int i;
- ucam_mod->ucmac = (struct bna_mac *)
- res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.mdl[0].kva;
- INIT_LIST_HEAD(&ucam_mod->free_q);
- for (i = 0; i < bna->ioceth.attr.num_ucmac; i++) {
- bfa_q_qe_init(&ucam_mod->ucmac[i].qe);
- list_add_tail(&ucam_mod->ucmac[i].qe, &ucam_mod->free_q);
- }
- ucam_mod->bna = bna;
- }
- static void
- bna_ucam_mod_uninit(struct bna_ucam_mod *ucam_mod)
- {
- struct list_head *qe;
- int i = 0;
- list_for_each(qe, &ucam_mod->free_q)
- i++;
- ucam_mod->bna = NULL;
- }
- static void
- bna_mcam_mod_init(struct bna_mcam_mod *mcam_mod, struct bna *bna,
- struct bna_res_info *res_info)
- {
- int i;
- mcam_mod->mcmac = (struct bna_mac *)
- res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.mdl[0].kva;
- INIT_LIST_HEAD(&mcam_mod->free_q);
- for (i = 0; i < bna->ioceth.attr.num_mcmac; i++) {
- bfa_q_qe_init(&mcam_mod->mcmac[i].qe);
- list_add_tail(&mcam_mod->mcmac[i].qe, &mcam_mod->free_q);
- }
- mcam_mod->mchandle = (struct bna_mcam_handle *)
- res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_u.mem_info.mdl[0].kva;
- INIT_LIST_HEAD(&mcam_mod->free_handle_q);
- for (i = 0; i < bna->ioceth.attr.num_mcmac; i++) {
- bfa_q_qe_init(&mcam_mod->mchandle[i].qe);
- list_add_tail(&mcam_mod->mchandle[i].qe,
- &mcam_mod->free_handle_q);
- }
- mcam_mod->bna = bna;
- }
- static void
- bna_mcam_mod_uninit(struct bna_mcam_mod *mcam_mod)
- {
- struct list_head *qe;
- int i;
- i = 0;
- list_for_each(qe, &mcam_mod->free_q) i++;
- i = 0;
- list_for_each(qe, &mcam_mod->free_handle_q) i++;
- mcam_mod->bna = NULL;
- }
- static void
- bna_bfi_stats_get(struct bna *bna)
- {
- struct bfi_enet_stats_req *stats_req = &bna->stats_mod.stats_get;
- bna->stats_mod.stats_get_busy = true;
- bfi_msgq_mhdr_set(stats_req->mh, BFI_MC_ENET,
- BFI_ENET_H2I_STATS_GET_REQ, 0, 0);
- stats_req->mh.num_entries = htons(
- bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_stats_req)));
- stats_req->stats_mask = htons(BFI_ENET_STATS_ALL);
- stats_req->tx_enet_mask = htonl(bna->tx_mod.rid_mask);
- stats_req->rx_enet_mask = htonl(bna->rx_mod.rid_mask);
- stats_req->host_buffer.a32.addr_hi = bna->stats.hw_stats_dma.msb;
- stats_req->host_buffer.a32.addr_lo = bna->stats.hw_stats_dma.lsb;
- bfa_msgq_cmd_set(&bna->stats_mod.stats_get_cmd, NULL, NULL,
- sizeof(struct bfi_enet_stats_req), &stats_req->mh);
- bfa_msgq_cmd_post(&bna->msgq, &bna->stats_mod.stats_get_cmd);
- }
- void
- bna_res_req(struct bna_res_info *res_info)
- {
- /* DMA memory for COMMON_MODULE */
- res_info[BNA_RES_MEM_T_COM].res_type = BNA_RES_T_MEM;
- res_info[BNA_RES_MEM_T_COM].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
- res_info[BNA_RES_MEM_T_COM].res_u.mem_info.num = 1;
- res_info[BNA_RES_MEM_T_COM].res_u.mem_info.len = ALIGN(
- (bfa_nw_cee_meminfo() +
- bfa_msgq_meminfo()), PAGE_SIZE);
- /* DMA memory for retrieving IOC attributes */
- res_info[BNA_RES_MEM_T_ATTR].res_type = BNA_RES_T_MEM;
- res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
- res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.num = 1;
- res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.len =
- ALIGN(bfa_nw_ioc_meminfo(), PAGE_SIZE);
- /* Virtual memory for retreiving fw_trc */
- res_info[BNA_RES_MEM_T_FWTRC].res_type = BNA_RES_T_MEM;
- res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.mem_type = BNA_MEM_T_KVA;
- res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.num = 0;
- res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.len = 0;
- /* DMA memory for retreiving stats */
- res_info[BNA_RES_MEM_T_STATS].res_type = BNA_RES_T_MEM;
- res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
- res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.num = 1;
- res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.len =
- ALIGN(sizeof(struct bfi_enet_stats),
- PAGE_SIZE);
- }
- void
- bna_mod_res_req(struct bna *bna, struct bna_res_info *res_info)
- {
- struct bna_attr *attr = &bna->ioceth.attr;
- /* Virtual memory for Tx objects - stored by Tx module */
- res_info[BNA_MOD_RES_MEM_T_TX_ARRAY].res_type = BNA_RES_T_MEM;
- res_info[BNA_MOD_RES_MEM_T_TX_ARRAY].res_u.mem_info.mem_type =
- BNA_MEM_T_KVA;
- res_info[BNA_MOD_RES_MEM_T_TX_ARRAY].res_u.mem_info.num = 1;
- res_info[BNA_MOD_RES_MEM_T_TX_ARRAY].res_u.mem_info.len =
- attr->num_txq * sizeof(struct bna_tx);
- /* Virtual memory for TxQ - stored by Tx module */
- res_info[BNA_MOD_RES_MEM_T_TXQ_ARRAY].res_type = BNA_RES_T_MEM;
- res_info[BNA_MOD_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.mem_type =
- BNA_MEM_T_KVA;
- res_info[BNA_MOD_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.num = 1;
- res_info[BNA_MOD_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.len =
- attr->num_txq * sizeof(struct bna_txq);
- /* Virtual memory for Rx objects - stored by Rx module */
- res_info[BNA_MOD_RES_MEM_T_RX_ARRAY].res_type = BNA_RES_T_MEM;
- res_info[BNA_MOD_RES_MEM_T_RX_ARRAY].res_u.mem_info.mem_type =
- BNA_MEM_T_KVA;
- res_info[BNA_MOD_RES_MEM_T_RX_ARRAY].res_u.mem_info.num = 1;
- res_info[BNA_MOD_RES_MEM_T_RX_ARRAY].res_u.mem_info.len =
- attr->num_rxp * sizeof(struct bna_rx);
- /* Virtual memory for RxPath - stored by Rx module */
- res_info[BNA_MOD_RES_MEM_T_RXP_ARRAY].res_type = BNA_RES_T_MEM;
- res_info[BNA_MOD_RES_MEM_T_RXP_ARRAY].res_u.mem_info.mem_type =
- BNA_MEM_T_KVA;
- res_info[BNA_MOD_RES_MEM_T_RXP_ARRAY].res_u.mem_info.num = 1;
- res_info[BNA_MOD_RES_MEM_T_RXP_ARRAY].res_u.mem_info.len =
- attr->num_rxp * sizeof(struct bna_rxp);
- /* Virtual memory for RxQ - stored by Rx module */
- res_info[BNA_MOD_RES_MEM_T_RXQ_ARRAY].res_type = BNA_RES_T_MEM;
- res_info[BNA_MOD_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.mem_type =
- BNA_MEM_T_KVA;
- res_info[BNA_MOD_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.num = 1;
- res_info[BNA_MOD_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.len =
- (attr->num_rxp * 2) * sizeof(struct bna_rxq);
- /* Virtual memory for Unicast MAC address - stored by ucam module */
- res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_type = BNA_RES_T_MEM;
- res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.mem_type =
- BNA_MEM_T_KVA;
- res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.num = 1;
- res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.len =
- attr->num_ucmac * sizeof(struct bna_mac);
- /* Virtual memory for Multicast MAC address - stored by mcam module */
- res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_type = BNA_RES_T_MEM;
- res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.mem_type =
- BNA_MEM_T_KVA;
- res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.num = 1;
- res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.len =
- attr->num_mcmac * sizeof(struct bna_mac);
- /* Virtual memory for Multicast handle - stored by mcam module */
- res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_type = BNA_RES_T_MEM;
- res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_u.mem_info.mem_type =
- BNA_MEM_T_KVA;
- res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_u.mem_info.num = 1;
- res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_u.mem_info.len =
- attr->num_mcmac * sizeof(struct bna_mcam_handle);
- }
- void
- bna_init(struct bna *bna, struct bnad *bnad,
- struct bfa_pcidev *pcidev, struct bna_res_info *res_info)
- {
- bna->bnad = bnad;
- bna->pcidev = *pcidev;
- bna->stats.hw_stats_kva = (struct bfi_enet_stats *)
- res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mdl[0].kva;
- bna->stats.hw_stats_dma.msb =
- res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mdl[0].dma.msb;
- bna->stats.hw_stats_dma.lsb =
- res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mdl[0].dma.lsb;
- bna_reg_addr_init(bna, &bna->pcidev);
- /* Also initializes diag, cee, sfp, phy_port, msgq */
- bna_ioceth_init(&bna->ioceth, bna, res_info);
- bna_enet_init(&bna->enet, bna);
- bna_ethport_init(&bna->ethport, bna);
- }
- void
- bna_mod_init(struct bna *bna, struct bna_res_info *res_info)
- {
- bna_tx_mod_init(&bna->tx_mod, bna, res_info);
- bna_rx_mod_init(&bna->rx_mod, bna, res_info);
- bna_ucam_mod_init(&bna->ucam_mod, bna, res_info);
- bna_mcam_mod_init(&bna->mcam_mod, bna, res_info);
- bna->default_mode_rid = BFI_INVALID_RID;
- bna->promisc_rid = BFI_INVALID_RID;
- bna->mod_flags |= BNA_MOD_F_INIT_DONE;
- }
- void
- bna_uninit(struct bna *bna)
- {
- if (bna->mod_flags & BNA_MOD_F_INIT_DONE) {
- bna_mcam_mod_uninit(&bna->mcam_mod);
- bna_ucam_mod_uninit(&bna->ucam_mod);
- bna_rx_mod_uninit(&bna->rx_mod);
- bna_tx_mod_uninit(&bna->tx_mod);
- bna->mod_flags &= ~BNA_MOD_F_INIT_DONE;
- }
- bna_stats_mod_uninit(&bna->stats_mod);
- bna_ethport_uninit(&bna->ethport);
- bna_enet_uninit(&bna->enet);
- bna_ioceth_uninit(&bna->ioceth);
- bna->bnad = NULL;
- }
- int
- bna_num_txq_set(struct bna *bna, int num_txq)
- {
- if (bna->ioceth.attr.fw_query_complete &&
- (num_txq <= bna->ioceth.attr.num_txq)) {
- bna->ioceth.attr.num_txq = num_txq;
- return BNA_CB_SUCCESS;
- }
- return BNA_CB_FAIL;
- }
- int
- bna_num_rxp_set(struct bna *bna, int num_rxp)
- {
- if (bna->ioceth.attr.fw_query_complete &&
- (num_rxp <= bna->ioceth.attr.num_rxp)) {
- bna->ioceth.attr.num_rxp = num_rxp;
- return BNA_CB_SUCCESS;
- }
- return BNA_CB_FAIL;
- }
- struct bna_mac *
- bna_ucam_mod_mac_get(struct bna_ucam_mod *ucam_mod)
- {
- struct list_head *qe;
- if (list_empty(&ucam_mod->free_q))
- return NULL;
- bfa_q_deq(&ucam_mod->free_q, &qe);
- return (struct bna_mac *)qe;
- }
- void
- bna_ucam_mod_mac_put(struct bna_ucam_mod *ucam_mod, struct bna_mac *mac)
- {
- list_add_tail(&mac->qe, &ucam_mod->free_q);
- }
- struct bna_mac *
- bna_mcam_mod_mac_get(struct bna_mcam_mod *mcam_mod)
- {
- struct list_head *qe;
- if (list_empty(&mcam_mod->free_q))
- return NULL;
- bfa_q_deq(&mcam_mod->free_q, &qe);
- return (struct bna_mac *)qe;
- }
- void
- bna_mcam_mod_mac_put(struct bna_mcam_mod *mcam_mod, struct bna_mac *mac)
- {
- list_add_tail(&mac->qe, &mcam_mod->free_q);
- }
- struct bna_mcam_handle *
- bna_mcam_mod_handle_get(struct bna_mcam_mod *mcam_mod)
- {
- struct list_head *qe;
- if (list_empty(&mcam_mod->free_handle_q))
- return NULL;
- bfa_q_deq(&mcam_mod->free_handle_q, &qe);
- return (struct bna_mcam_handle *)qe;
- }
- void
- bna_mcam_mod_handle_put(struct bna_mcam_mod *mcam_mod,
- struct bna_mcam_handle *handle)
- {
- list_add_tail(&handle->qe, &mcam_mod->free_handle_q);
- }
- void
- bna_hw_stats_get(struct bna *bna)
- {
- if (!bna->stats_mod.ioc_ready) {
- bnad_cb_stats_get(bna->bnad, BNA_CB_FAIL, &bna->stats);
- return;
- }
- if (bna->stats_mod.stats_get_busy) {
- bnad_cb_stats_get(bna->bnad, BNA_CB_BUSY, &bna->stats);
- return;
- }
- bna_bfi_stats_get(bna);
- }
|