bond_3ad.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
  4. */
  5. #include <linux/skbuff.h>
  6. #include <linux/if_ether.h>
  7. #include <linux/netdevice.h>
  8. #include <linux/spinlock.h>
  9. #include <linux/ethtool.h>
  10. #include <linux/etherdevice.h>
  11. #include <linux/if_bonding.h>
  12. #include <linux/pkt_sched.h>
  13. #include <net/net_namespace.h>
  14. #include <net/bonding.h>
  15. #include <net/bond_3ad.h>
  16. #include <net/netlink.h>
  17. /* General definitions */
  18. #define AD_SHORT_TIMEOUT 1
  19. #define AD_LONG_TIMEOUT 0
  20. #define AD_STANDBY 0x2
  21. #define AD_MAX_TX_IN_SECOND 3
  22. #define AD_COLLECTOR_MAX_DELAY 0
  23. /* Timer definitions (43.4.4 in the 802.3ad standard) */
  24. #define AD_FAST_PERIODIC_TIME 1
  25. #define AD_SLOW_PERIODIC_TIME 30
  26. #define AD_SHORT_TIMEOUT_TIME (3*AD_FAST_PERIODIC_TIME)
  27. #define AD_LONG_TIMEOUT_TIME (3*AD_SLOW_PERIODIC_TIME)
  28. #define AD_CHURN_DETECTION_TIME 60
  29. #define AD_AGGREGATE_WAIT_TIME 2
  30. /* Port Variables definitions used by the State Machines (43.4.7 in the
  31. * 802.3ad standard)
  32. */
  33. #define AD_PORT_BEGIN 0x1
  34. #define AD_PORT_LACP_ENABLED 0x2
  35. #define AD_PORT_ACTOR_CHURN 0x4
  36. #define AD_PORT_PARTNER_CHURN 0x8
  37. #define AD_PORT_READY 0x10
  38. #define AD_PORT_READY_N 0x20
  39. #define AD_PORT_MATCHED 0x40
  40. #define AD_PORT_STANDBY 0x80
  41. #define AD_PORT_SELECTED 0x100
  42. #define AD_PORT_MOVED 0x200
  43. #define AD_PORT_CHURNED (AD_PORT_ACTOR_CHURN | AD_PORT_PARTNER_CHURN)
  44. /* Port Key definitions
  45. * key is determined according to the link speed, duplex and
  46. * user key (which is yet not supported)
  47. * --------------------------------------------------------------
  48. * Port key | User key (10 bits) | Speed (5 bits) | Duplex|
  49. * --------------------------------------------------------------
  50. * |15 6|5 1|0
  51. */
  52. #define AD_DUPLEX_KEY_MASKS 0x1
  53. #define AD_SPEED_KEY_MASKS 0x3E
  54. #define AD_USER_KEY_MASKS 0xFFC0
  55. enum ad_link_speed_type {
  56. AD_LINK_SPEED_1MBPS = 1,
  57. AD_LINK_SPEED_10MBPS,
  58. AD_LINK_SPEED_100MBPS,
  59. AD_LINK_SPEED_1000MBPS,
  60. AD_LINK_SPEED_2500MBPS,
  61. AD_LINK_SPEED_5000MBPS,
  62. AD_LINK_SPEED_10000MBPS,
  63. AD_LINK_SPEED_14000MBPS,
  64. AD_LINK_SPEED_20000MBPS,
  65. AD_LINK_SPEED_25000MBPS,
  66. AD_LINK_SPEED_40000MBPS,
  67. AD_LINK_SPEED_50000MBPS,
  68. AD_LINK_SPEED_56000MBPS,
  69. AD_LINK_SPEED_100000MBPS,
  70. AD_LINK_SPEED_200000MBPS,
  71. AD_LINK_SPEED_400000MBPS,
  72. };
  73. /* compare MAC addresses */
  74. #define MAC_ADDRESS_EQUAL(A, B) \
  75. ether_addr_equal_64bits((const u8 *)A, (const u8 *)B)
  76. static const u8 null_mac_addr[ETH_ALEN + 2] __long_aligned = {
  77. 0, 0, 0, 0, 0, 0
  78. };
  79. static const u16 ad_ticks_per_sec = 1000 / AD_TIMER_INTERVAL;
  80. static const int ad_delta_in_ticks = (AD_TIMER_INTERVAL * HZ) / 1000;
  81. const u8 lacpdu_mcast_addr[ETH_ALEN + 2] __long_aligned = {
  82. 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02
  83. };
  84. /* ================= main 802.3ad protocol functions ================== */
  85. static int ad_lacpdu_send(struct port *port);
  86. static int ad_marker_send(struct port *port, struct bond_marker *marker);
  87. static void ad_mux_machine(struct port *port, bool *update_slave_arr);
  88. static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port);
  89. static void ad_tx_machine(struct port *port);
  90. static void ad_periodic_machine(struct port *port, struct bond_params *bond_params);
  91. static void ad_port_selection_logic(struct port *port, bool *update_slave_arr);
  92. static void ad_agg_selection_logic(struct aggregator *aggregator,
  93. bool *update_slave_arr);
  94. static void ad_clear_agg(struct aggregator *aggregator);
  95. static void ad_initialize_agg(struct aggregator *aggregator);
  96. static void ad_initialize_port(struct port *port, int lacp_fast);
  97. static void ad_enable_collecting_distributing(struct port *port,
  98. bool *update_slave_arr);
  99. static void ad_disable_collecting_distributing(struct port *port,
  100. bool *update_slave_arr);
  101. static void ad_marker_info_received(struct bond_marker *marker_info,
  102. struct port *port);
  103. static void ad_marker_response_received(struct bond_marker *marker,
  104. struct port *port);
  105. static void ad_update_actor_keys(struct port *port, bool reset);
  106. /* ================= api to bonding and kernel code ================== */
  107. /**
  108. * __get_bond_by_port - get the port's bonding struct
  109. * @port: the port we're looking at
  110. *
  111. * Return @port's bonding struct, or %NULL if it can't be found.
  112. */
  113. static inline struct bonding *__get_bond_by_port(struct port *port)
  114. {
  115. if (port->slave == NULL)
  116. return NULL;
  117. return bond_get_bond_by_slave(port->slave);
  118. }
  119. /**
  120. * __get_first_agg - get the first aggregator in the bond
  121. * @port: the port we're looking at
  122. *
  123. * Return the aggregator of the first slave in @bond, or %NULL if it can't be
  124. * found.
  125. * The caller must hold RCU or RTNL lock.
  126. */
  127. static inline struct aggregator *__get_first_agg(struct port *port)
  128. {
  129. struct bonding *bond = __get_bond_by_port(port);
  130. struct slave *first_slave;
  131. struct aggregator *agg;
  132. /* If there's no bond for this port, or bond has no slaves */
  133. if (bond == NULL)
  134. return NULL;
  135. rcu_read_lock();
  136. first_slave = bond_first_slave_rcu(bond);
  137. agg = first_slave ? &(SLAVE_AD_INFO(first_slave)->aggregator) : NULL;
  138. rcu_read_unlock();
  139. return agg;
  140. }
  141. /**
  142. * __agg_has_partner - see if we have a partner
  143. * @agg: the agregator we're looking at
  144. *
  145. * Return nonzero if aggregator has a partner (denoted by a non-zero ether
  146. * address for the partner). Return 0 if not.
  147. */
  148. static inline int __agg_has_partner(struct aggregator *agg)
  149. {
  150. return !is_zero_ether_addr(agg->partner_system.mac_addr_value);
  151. }
  152. /**
  153. * __disable_port - disable the port's slave
  154. * @port: the port we're looking at
  155. */
  156. static inline void __disable_port(struct port *port)
  157. {
  158. bond_set_slave_inactive_flags(port->slave, BOND_SLAVE_NOTIFY_LATER);
  159. }
  160. /**
  161. * __enable_port - enable the port's slave, if it's up
  162. * @port: the port we're looking at
  163. */
  164. static inline void __enable_port(struct port *port)
  165. {
  166. struct slave *slave = port->slave;
  167. if ((slave->link == BOND_LINK_UP) && bond_slave_is_up(slave))
  168. bond_set_slave_active_flags(slave, BOND_SLAVE_NOTIFY_LATER);
  169. }
  170. /**
  171. * __port_is_enabled - check if the port's slave is in active state
  172. * @port: the port we're looking at
  173. */
  174. static inline int __port_is_enabled(struct port *port)
  175. {
  176. return bond_is_active_slave(port->slave);
  177. }
  178. /**
  179. * __get_agg_selection_mode - get the aggregator selection mode
  180. * @port: the port we're looking at
  181. *
  182. * Get the aggregator selection mode. Can be %STABLE, %BANDWIDTH or %COUNT.
  183. */
  184. static inline u32 __get_agg_selection_mode(struct port *port)
  185. {
  186. struct bonding *bond = __get_bond_by_port(port);
  187. if (bond == NULL)
  188. return BOND_AD_STABLE;
  189. return bond->params.ad_select;
  190. }
  191. /**
  192. * __check_agg_selection_timer - check if the selection timer has expired
  193. * @port: the port we're looking at
  194. */
  195. static inline int __check_agg_selection_timer(struct port *port)
  196. {
  197. struct bonding *bond = __get_bond_by_port(port);
  198. if (bond == NULL)
  199. return 0;
  200. return atomic_read(&BOND_AD_INFO(bond).agg_select_timer) ? 1 : 0;
  201. }
  202. /**
  203. * __get_link_speed - get a port's speed
  204. * @port: the port we're looking at
  205. *
  206. * Return @port's speed in 802.3ad enum format. i.e. one of:
  207. * 0,
  208. * %AD_LINK_SPEED_10MBPS,
  209. * %AD_LINK_SPEED_100MBPS,
  210. * %AD_LINK_SPEED_1000MBPS,
  211. * %AD_LINK_SPEED_2500MBPS,
  212. * %AD_LINK_SPEED_5000MBPS,
  213. * %AD_LINK_SPEED_10000MBPS
  214. * %AD_LINK_SPEED_14000MBPS,
  215. * %AD_LINK_SPEED_20000MBPS
  216. * %AD_LINK_SPEED_25000MBPS
  217. * %AD_LINK_SPEED_40000MBPS
  218. * %AD_LINK_SPEED_50000MBPS
  219. * %AD_LINK_SPEED_56000MBPS
  220. * %AD_LINK_SPEED_100000MBPS
  221. * %AD_LINK_SPEED_200000MBPS
  222. * %AD_LINK_SPEED_400000MBPS
  223. */
  224. static u16 __get_link_speed(struct port *port)
  225. {
  226. struct slave *slave = port->slave;
  227. u16 speed;
  228. /* this if covers only a special case: when the configuration starts
  229. * with link down, it sets the speed to 0.
  230. * This is done in spite of the fact that the e100 driver reports 0
  231. * to be compatible with MVT in the future.
  232. */
  233. if (slave->link != BOND_LINK_UP)
  234. speed = 0;
  235. else {
  236. switch (slave->speed) {
  237. case SPEED_10:
  238. speed = AD_LINK_SPEED_10MBPS;
  239. break;
  240. case SPEED_100:
  241. speed = AD_LINK_SPEED_100MBPS;
  242. break;
  243. case SPEED_1000:
  244. speed = AD_LINK_SPEED_1000MBPS;
  245. break;
  246. case SPEED_2500:
  247. speed = AD_LINK_SPEED_2500MBPS;
  248. break;
  249. case SPEED_5000:
  250. speed = AD_LINK_SPEED_5000MBPS;
  251. break;
  252. case SPEED_10000:
  253. speed = AD_LINK_SPEED_10000MBPS;
  254. break;
  255. case SPEED_14000:
  256. speed = AD_LINK_SPEED_14000MBPS;
  257. break;
  258. case SPEED_20000:
  259. speed = AD_LINK_SPEED_20000MBPS;
  260. break;
  261. case SPEED_25000:
  262. speed = AD_LINK_SPEED_25000MBPS;
  263. break;
  264. case SPEED_40000:
  265. speed = AD_LINK_SPEED_40000MBPS;
  266. break;
  267. case SPEED_50000:
  268. speed = AD_LINK_SPEED_50000MBPS;
  269. break;
  270. case SPEED_56000:
  271. speed = AD_LINK_SPEED_56000MBPS;
  272. break;
  273. case SPEED_100000:
  274. speed = AD_LINK_SPEED_100000MBPS;
  275. break;
  276. case SPEED_200000:
  277. speed = AD_LINK_SPEED_200000MBPS;
  278. break;
  279. case SPEED_400000:
  280. speed = AD_LINK_SPEED_400000MBPS;
  281. break;
  282. default:
  283. /* unknown speed value from ethtool. shouldn't happen */
  284. if (slave->speed != SPEED_UNKNOWN)
  285. pr_err_once("%s: (slave %s): unknown ethtool speed (%d) for port %d (set it to 0)\n",
  286. slave->bond->dev->name,
  287. slave->dev->name, slave->speed,
  288. port->actor_port_number);
  289. speed = 0;
  290. break;
  291. }
  292. }
  293. slave_dbg(slave->bond->dev, slave->dev, "Port %d Received link speed %d update from adapter\n",
  294. port->actor_port_number, speed);
  295. return speed;
  296. }
  297. /**
  298. * __get_duplex - get a port's duplex
  299. * @port: the port we're looking at
  300. *
  301. * Return @port's duplex in 802.3ad bitmask format. i.e.:
  302. * 0x01 if in full duplex
  303. * 0x00 otherwise
  304. */
  305. static u8 __get_duplex(struct port *port)
  306. {
  307. struct slave *slave = port->slave;
  308. u8 retval = 0x0;
  309. /* handling a special case: when the configuration starts with
  310. * link down, it sets the duplex to 0.
  311. */
  312. if (slave->link == BOND_LINK_UP) {
  313. switch (slave->duplex) {
  314. case DUPLEX_FULL:
  315. retval = 0x1;
  316. slave_dbg(slave->bond->dev, slave->dev, "Port %d Received status full duplex update from adapter\n",
  317. port->actor_port_number);
  318. break;
  319. case DUPLEX_HALF:
  320. default:
  321. retval = 0x0;
  322. slave_dbg(slave->bond->dev, slave->dev, "Port %d Received status NOT full duplex update from adapter\n",
  323. port->actor_port_number);
  324. break;
  325. }
  326. }
  327. return retval;
  328. }
  329. static void __ad_actor_update_port(struct port *port)
  330. {
  331. const struct bonding *bond = bond_get_bond_by_slave(port->slave);
  332. port->actor_system = BOND_AD_INFO(bond).system.sys_mac_addr;
  333. port->actor_system_priority = BOND_AD_INFO(bond).system.sys_priority;
  334. }
  335. /* Conversions */
  336. /**
  337. * __ad_timer_to_ticks - convert a given timer type to AD module ticks
  338. * @timer_type: which timer to operate
  339. * @par: timer parameter. see below
  340. *
  341. * If @timer_type is %current_while_timer, @par indicates long/short timer.
  342. * If @timer_type is %periodic_timer, @par is one of %FAST_PERIODIC_TIME,
  343. * %SLOW_PERIODIC_TIME.
  344. */
  345. static u16 __ad_timer_to_ticks(u16 timer_type, u16 par)
  346. {
  347. u16 retval = 0; /* to silence the compiler */
  348. switch (timer_type) {
  349. case AD_CURRENT_WHILE_TIMER: /* for rx machine usage */
  350. if (par)
  351. retval = (AD_SHORT_TIMEOUT_TIME*ad_ticks_per_sec);
  352. else
  353. retval = (AD_LONG_TIMEOUT_TIME*ad_ticks_per_sec);
  354. break;
  355. case AD_ACTOR_CHURN_TIMER: /* for local churn machine */
  356. retval = (AD_CHURN_DETECTION_TIME*ad_ticks_per_sec);
  357. break;
  358. case AD_PERIODIC_TIMER: /* for periodic machine */
  359. retval = (par*ad_ticks_per_sec); /* long timeout */
  360. break;
  361. case AD_PARTNER_CHURN_TIMER: /* for remote churn machine */
  362. retval = (AD_CHURN_DETECTION_TIME*ad_ticks_per_sec);
  363. break;
  364. case AD_WAIT_WHILE_TIMER: /* for selection machine */
  365. retval = (AD_AGGREGATE_WAIT_TIME*ad_ticks_per_sec);
  366. break;
  367. }
  368. return retval;
  369. }
  370. /* ================= ad_rx_machine helper functions ================== */
  371. /**
  372. * __choose_matched - update a port's matched variable from a received lacpdu
  373. * @lacpdu: the lacpdu we've received
  374. * @port: the port we're looking at
  375. *
  376. * Update the value of the matched variable, using parameter values from a
  377. * newly received lacpdu. Parameter values for the partner carried in the
  378. * received PDU are compared with the corresponding operational parameter
  379. * values for the actor. Matched is set to TRUE if all of these parameters
  380. * match and the PDU parameter partner_state.aggregation has the same value as
  381. * actor_oper_port_state.aggregation and lacp will actively maintain the link
  382. * in the aggregation. Matched is also set to TRUE if the value of
  383. * actor_state.aggregation in the received PDU is set to FALSE, i.e., indicates
  384. * an individual link and lacp will actively maintain the link. Otherwise,
  385. * matched is set to FALSE. LACP is considered to be actively maintaining the
  386. * link if either the PDU's actor_state.lacp_activity variable is TRUE or both
  387. * the actor's actor_oper_port_state.lacp_activity and the PDU's
  388. * partner_state.lacp_activity variables are TRUE.
  389. *
  390. * Note: the AD_PORT_MATCHED "variable" is not specified by 802.3ad; it is
  391. * used here to implement the language from 802.3ad 43.4.9 that requires
  392. * recordPDU to "match" the LACPDU parameters to the stored values.
  393. */
  394. static void __choose_matched(struct lacpdu *lacpdu, struct port *port)
  395. {
  396. /* check if all parameters are alike
  397. * or this is individual link(aggregation == FALSE)
  398. * then update the state machine Matched variable.
  399. */
  400. if (((ntohs(lacpdu->partner_port) == port->actor_port_number) &&
  401. (ntohs(lacpdu->partner_port_priority) == port->actor_port_priority) &&
  402. MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) &&
  403. (ntohs(lacpdu->partner_system_priority) == port->actor_system_priority) &&
  404. (ntohs(lacpdu->partner_key) == port->actor_oper_port_key) &&
  405. ((lacpdu->partner_state & LACP_STATE_AGGREGATION) == (port->actor_oper_port_state & LACP_STATE_AGGREGATION))) ||
  406. ((lacpdu->actor_state & LACP_STATE_AGGREGATION) == 0)
  407. ) {
  408. port->sm_vars |= AD_PORT_MATCHED;
  409. } else {
  410. port->sm_vars &= ~AD_PORT_MATCHED;
  411. }
  412. }
  413. /**
  414. * __record_pdu - record parameters from a received lacpdu
  415. * @lacpdu: the lacpdu we've received
  416. * @port: the port we're looking at
  417. *
  418. * Record the parameter values for the Actor carried in a received lacpdu as
  419. * the current partner operational parameter values and sets
  420. * actor_oper_port_state.defaulted to FALSE.
  421. */
  422. static void __record_pdu(struct lacpdu *lacpdu, struct port *port)
  423. {
  424. if (lacpdu && port) {
  425. struct port_params *partner = &port->partner_oper;
  426. __choose_matched(lacpdu, port);
  427. /* record the new parameter values for the partner
  428. * operational
  429. */
  430. partner->port_number = ntohs(lacpdu->actor_port);
  431. partner->port_priority = ntohs(lacpdu->actor_port_priority);
  432. partner->system = lacpdu->actor_system;
  433. partner->system_priority = ntohs(lacpdu->actor_system_priority);
  434. partner->key = ntohs(lacpdu->actor_key);
  435. partner->port_state = lacpdu->actor_state;
  436. /* set actor_oper_port_state.defaulted to FALSE */
  437. port->actor_oper_port_state &= ~LACP_STATE_DEFAULTED;
  438. /* set the partner sync. to on if the partner is sync,
  439. * and the port is matched
  440. */
  441. if ((port->sm_vars & AD_PORT_MATCHED) &&
  442. (lacpdu->actor_state & LACP_STATE_SYNCHRONIZATION)) {
  443. partner->port_state |= LACP_STATE_SYNCHRONIZATION;
  444. slave_dbg(port->slave->bond->dev, port->slave->dev,
  445. "partner sync=1\n");
  446. } else {
  447. partner->port_state &= ~LACP_STATE_SYNCHRONIZATION;
  448. slave_dbg(port->slave->bond->dev, port->slave->dev,
  449. "partner sync=0\n");
  450. }
  451. }
  452. }
  453. /**
  454. * __record_default - record default parameters
  455. * @port: the port we're looking at
  456. *
  457. * This function records the default parameter values for the partner carried
  458. * in the Partner Admin parameters as the current partner operational parameter
  459. * values and sets actor_oper_port_state.defaulted to TRUE.
  460. */
  461. static void __record_default(struct port *port)
  462. {
  463. if (port) {
  464. /* record the partner admin parameters */
  465. memcpy(&port->partner_oper, &port->partner_admin,
  466. sizeof(struct port_params));
  467. /* set actor_oper_port_state.defaulted to true */
  468. port->actor_oper_port_state |= LACP_STATE_DEFAULTED;
  469. }
  470. }
  471. /**
  472. * __update_selected - update a port's Selected variable from a received lacpdu
  473. * @lacpdu: the lacpdu we've received
  474. * @port: the port we're looking at
  475. *
  476. * Update the value of the selected variable, using parameter values from a
  477. * newly received lacpdu. The parameter values for the Actor carried in the
  478. * received PDU are compared with the corresponding operational parameter
  479. * values for the ports partner. If one or more of the comparisons shows that
  480. * the value(s) received in the PDU differ from the current operational values,
  481. * then selected is set to FALSE and actor_oper_port_state.synchronization is
  482. * set to out_of_sync. Otherwise, selected remains unchanged.
  483. */
  484. static void __update_selected(struct lacpdu *lacpdu, struct port *port)
  485. {
  486. if (lacpdu && port) {
  487. const struct port_params *partner = &port->partner_oper;
  488. /* check if any parameter is different then
  489. * update the state machine selected variable.
  490. */
  491. if (ntohs(lacpdu->actor_port) != partner->port_number ||
  492. ntohs(lacpdu->actor_port_priority) != partner->port_priority ||
  493. !MAC_ADDRESS_EQUAL(&lacpdu->actor_system, &partner->system) ||
  494. ntohs(lacpdu->actor_system_priority) != partner->system_priority ||
  495. ntohs(lacpdu->actor_key) != partner->key ||
  496. (lacpdu->actor_state & LACP_STATE_AGGREGATION) != (partner->port_state & LACP_STATE_AGGREGATION)) {
  497. port->sm_vars &= ~AD_PORT_SELECTED;
  498. }
  499. }
  500. }
  501. /**
  502. * __update_default_selected - update a port's Selected variable from Partner
  503. * @port: the port we're looking at
  504. *
  505. * This function updates the value of the selected variable, using the partner
  506. * administrative parameter values. The administrative values are compared with
  507. * the corresponding operational parameter values for the partner. If one or
  508. * more of the comparisons shows that the administrative value(s) differ from
  509. * the current operational values, then Selected is set to FALSE and
  510. * actor_oper_port_state.synchronization is set to OUT_OF_SYNC. Otherwise,
  511. * Selected remains unchanged.
  512. */
  513. static void __update_default_selected(struct port *port)
  514. {
  515. if (port) {
  516. const struct port_params *admin = &port->partner_admin;
  517. const struct port_params *oper = &port->partner_oper;
  518. /* check if any parameter is different then
  519. * update the state machine selected variable.
  520. */
  521. if (admin->port_number != oper->port_number ||
  522. admin->port_priority != oper->port_priority ||
  523. !MAC_ADDRESS_EQUAL(&admin->system, &oper->system) ||
  524. admin->system_priority != oper->system_priority ||
  525. admin->key != oper->key ||
  526. (admin->port_state & LACP_STATE_AGGREGATION)
  527. != (oper->port_state & LACP_STATE_AGGREGATION)) {
  528. port->sm_vars &= ~AD_PORT_SELECTED;
  529. }
  530. }
  531. }
  532. /**
  533. * __update_ntt - update a port's ntt variable from a received lacpdu
  534. * @lacpdu: the lacpdu we've received
  535. * @port: the port we're looking at
  536. *
  537. * Updates the value of the ntt variable, using parameter values from a newly
  538. * received lacpdu. The parameter values for the partner carried in the
  539. * received PDU are compared with the corresponding operational parameter
  540. * values for the Actor. If one or more of the comparisons shows that the
  541. * value(s) received in the PDU differ from the current operational values,
  542. * then ntt is set to TRUE. Otherwise, ntt remains unchanged.
  543. */
  544. static void __update_ntt(struct lacpdu *lacpdu, struct port *port)
  545. {
  546. /* validate lacpdu and port */
  547. if (lacpdu && port) {
  548. /* check if any parameter is different then
  549. * update the port->ntt.
  550. */
  551. if ((ntohs(lacpdu->partner_port) != port->actor_port_number) ||
  552. (ntohs(lacpdu->partner_port_priority) != port->actor_port_priority) ||
  553. !MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) ||
  554. (ntohs(lacpdu->partner_system_priority) != port->actor_system_priority) ||
  555. (ntohs(lacpdu->partner_key) != port->actor_oper_port_key) ||
  556. ((lacpdu->partner_state & LACP_STATE_LACP_ACTIVITY) != (port->actor_oper_port_state & LACP_STATE_LACP_ACTIVITY)) ||
  557. ((lacpdu->partner_state & LACP_STATE_LACP_TIMEOUT) != (port->actor_oper_port_state & LACP_STATE_LACP_TIMEOUT)) ||
  558. ((lacpdu->partner_state & LACP_STATE_SYNCHRONIZATION) != (port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION)) ||
  559. ((lacpdu->partner_state & LACP_STATE_AGGREGATION) != (port->actor_oper_port_state & LACP_STATE_AGGREGATION))
  560. ) {
  561. port->ntt = true;
  562. }
  563. }
  564. }
  565. /**
  566. * __agg_ports_are_ready - check if all ports in an aggregator are ready
  567. * @aggregator: the aggregator we're looking at
  568. *
  569. */
  570. static int __agg_ports_are_ready(struct aggregator *aggregator)
  571. {
  572. struct port *port;
  573. int retval = 1;
  574. if (aggregator) {
  575. /* scan all ports in this aggregator to verfy if they are
  576. * all ready.
  577. */
  578. for (port = aggregator->lag_ports;
  579. port;
  580. port = port->next_port_in_aggregator) {
  581. if (!(port->sm_vars & AD_PORT_READY_N)) {
  582. retval = 0;
  583. break;
  584. }
  585. }
  586. }
  587. return retval;
  588. }
  589. /**
  590. * __set_agg_ports_ready - set value of Ready bit in all ports of an aggregator
  591. * @aggregator: the aggregator we're looking at
  592. * @val: Should the ports' ready bit be set on or off
  593. *
  594. */
  595. static void __set_agg_ports_ready(struct aggregator *aggregator, int val)
  596. {
  597. struct port *port;
  598. for (port = aggregator->lag_ports; port;
  599. port = port->next_port_in_aggregator) {
  600. if (val)
  601. port->sm_vars |= AD_PORT_READY;
  602. else
  603. port->sm_vars &= ~AD_PORT_READY;
  604. }
  605. }
  606. static int __agg_active_ports(struct aggregator *agg)
  607. {
  608. struct port *port;
  609. int active = 0;
  610. for (port = agg->lag_ports; port;
  611. port = port->next_port_in_aggregator) {
  612. if (port->is_enabled)
  613. active++;
  614. }
  615. return active;
  616. }
  617. /**
  618. * __get_agg_bandwidth - get the total bandwidth of an aggregator
  619. * @aggregator: the aggregator we're looking at
  620. *
  621. */
  622. static u32 __get_agg_bandwidth(struct aggregator *aggregator)
  623. {
  624. int nports = __agg_active_ports(aggregator);
  625. u32 bandwidth = 0;
  626. if (nports) {
  627. switch (__get_link_speed(aggregator->lag_ports)) {
  628. case AD_LINK_SPEED_1MBPS:
  629. bandwidth = nports;
  630. break;
  631. case AD_LINK_SPEED_10MBPS:
  632. bandwidth = nports * 10;
  633. break;
  634. case AD_LINK_SPEED_100MBPS:
  635. bandwidth = nports * 100;
  636. break;
  637. case AD_LINK_SPEED_1000MBPS:
  638. bandwidth = nports * 1000;
  639. break;
  640. case AD_LINK_SPEED_2500MBPS:
  641. bandwidth = nports * 2500;
  642. break;
  643. case AD_LINK_SPEED_5000MBPS:
  644. bandwidth = nports * 5000;
  645. break;
  646. case AD_LINK_SPEED_10000MBPS:
  647. bandwidth = nports * 10000;
  648. break;
  649. case AD_LINK_SPEED_14000MBPS:
  650. bandwidth = nports * 14000;
  651. break;
  652. case AD_LINK_SPEED_20000MBPS:
  653. bandwidth = nports * 20000;
  654. break;
  655. case AD_LINK_SPEED_25000MBPS:
  656. bandwidth = nports * 25000;
  657. break;
  658. case AD_LINK_SPEED_40000MBPS:
  659. bandwidth = nports * 40000;
  660. break;
  661. case AD_LINK_SPEED_50000MBPS:
  662. bandwidth = nports * 50000;
  663. break;
  664. case AD_LINK_SPEED_56000MBPS:
  665. bandwidth = nports * 56000;
  666. break;
  667. case AD_LINK_SPEED_100000MBPS:
  668. bandwidth = nports * 100000;
  669. break;
  670. case AD_LINK_SPEED_200000MBPS:
  671. bandwidth = nports * 200000;
  672. break;
  673. case AD_LINK_SPEED_400000MBPS:
  674. bandwidth = nports * 400000;
  675. break;
  676. default:
  677. bandwidth = 0; /* to silence the compiler */
  678. }
  679. }
  680. return bandwidth;
  681. }
  682. /**
  683. * __get_active_agg - get the current active aggregator
  684. * @aggregator: the aggregator we're looking at
  685. *
  686. * Caller must hold RCU lock.
  687. */
  688. static struct aggregator *__get_active_agg(struct aggregator *aggregator)
  689. {
  690. struct bonding *bond = aggregator->slave->bond;
  691. struct list_head *iter;
  692. struct slave *slave;
  693. bond_for_each_slave_rcu(bond, slave, iter)
  694. if (SLAVE_AD_INFO(slave)->aggregator.is_active)
  695. return &(SLAVE_AD_INFO(slave)->aggregator);
  696. return NULL;
  697. }
  698. /**
  699. * __update_lacpdu_from_port - update a port's lacpdu fields
  700. * @port: the port we're looking at
  701. */
  702. static inline void __update_lacpdu_from_port(struct port *port)
  703. {
  704. struct lacpdu *lacpdu = &port->lacpdu;
  705. const struct port_params *partner = &port->partner_oper;
  706. /* update current actual Actor parameters
  707. * lacpdu->subtype initialized
  708. * lacpdu->version_number initialized
  709. * lacpdu->tlv_type_actor_info initialized
  710. * lacpdu->actor_information_length initialized
  711. */
  712. lacpdu->actor_system_priority = htons(port->actor_system_priority);
  713. lacpdu->actor_system = port->actor_system;
  714. lacpdu->actor_key = htons(port->actor_oper_port_key);
  715. lacpdu->actor_port_priority = htons(port->actor_port_priority);
  716. lacpdu->actor_port = htons(port->actor_port_number);
  717. lacpdu->actor_state = port->actor_oper_port_state;
  718. slave_dbg(port->slave->bond->dev, port->slave->dev,
  719. "update lacpdu: actor port state %x\n",
  720. port->actor_oper_port_state);
  721. /* lacpdu->reserved_3_1 initialized
  722. * lacpdu->tlv_type_partner_info initialized
  723. * lacpdu->partner_information_length initialized
  724. */
  725. lacpdu->partner_system_priority = htons(partner->system_priority);
  726. lacpdu->partner_system = partner->system;
  727. lacpdu->partner_key = htons(partner->key);
  728. lacpdu->partner_port_priority = htons(partner->port_priority);
  729. lacpdu->partner_port = htons(partner->port_number);
  730. lacpdu->partner_state = partner->port_state;
  731. /* lacpdu->reserved_3_2 initialized
  732. * lacpdu->tlv_type_collector_info initialized
  733. * lacpdu->collector_information_length initialized
  734. * collector_max_delay initialized
  735. * reserved_12[12] initialized
  736. * tlv_type_terminator initialized
  737. * terminator_length initialized
  738. * reserved_50[50] initialized
  739. */
  740. }
  741. /* ================= main 802.3ad protocol code ========================= */
  742. /**
  743. * ad_lacpdu_send - send out a lacpdu packet on a given port
  744. * @port: the port we're looking at
  745. *
  746. * Returns: 0 on success
  747. * < 0 on error
  748. */
  749. static int ad_lacpdu_send(struct port *port)
  750. {
  751. struct slave *slave = port->slave;
  752. struct sk_buff *skb;
  753. struct lacpdu_header *lacpdu_header;
  754. int length = sizeof(struct lacpdu_header);
  755. skb = dev_alloc_skb(length);
  756. if (!skb)
  757. return -ENOMEM;
  758. atomic64_inc(&SLAVE_AD_INFO(slave)->stats.lacpdu_tx);
  759. atomic64_inc(&BOND_AD_INFO(slave->bond).stats.lacpdu_tx);
  760. skb->dev = slave->dev;
  761. skb_reset_mac_header(skb);
  762. skb->network_header = skb->mac_header + ETH_HLEN;
  763. skb->protocol = PKT_TYPE_LACPDU;
  764. skb->priority = TC_PRIO_CONTROL;
  765. lacpdu_header = skb_put(skb, length);
  766. ether_addr_copy(lacpdu_header->hdr.h_dest, lacpdu_mcast_addr);
  767. /* Note: source address is set to be the member's PERMANENT address,
  768. * because we use it to identify loopback lacpdus in receive.
  769. */
  770. ether_addr_copy(lacpdu_header->hdr.h_source, slave->perm_hwaddr);
  771. lacpdu_header->hdr.h_proto = PKT_TYPE_LACPDU;
  772. lacpdu_header->lacpdu = port->lacpdu;
  773. dev_queue_xmit(skb);
  774. return 0;
  775. }
  776. /**
  777. * ad_marker_send - send marker information/response on a given port
  778. * @port: the port we're looking at
  779. * @marker: marker data to send
  780. *
  781. * Returns: 0 on success
  782. * < 0 on error
  783. */
  784. static int ad_marker_send(struct port *port, struct bond_marker *marker)
  785. {
  786. struct slave *slave = port->slave;
  787. struct sk_buff *skb;
  788. struct bond_marker_header *marker_header;
  789. int length = sizeof(struct bond_marker_header);
  790. skb = dev_alloc_skb(length + 16);
  791. if (!skb)
  792. return -ENOMEM;
  793. switch (marker->tlv_type) {
  794. case AD_MARKER_INFORMATION_SUBTYPE:
  795. atomic64_inc(&SLAVE_AD_INFO(slave)->stats.marker_tx);
  796. atomic64_inc(&BOND_AD_INFO(slave->bond).stats.marker_tx);
  797. break;
  798. case AD_MARKER_RESPONSE_SUBTYPE:
  799. atomic64_inc(&SLAVE_AD_INFO(slave)->stats.marker_resp_tx);
  800. atomic64_inc(&BOND_AD_INFO(slave->bond).stats.marker_resp_tx);
  801. break;
  802. }
  803. skb_reserve(skb, 16);
  804. skb->dev = slave->dev;
  805. skb_reset_mac_header(skb);
  806. skb->network_header = skb->mac_header + ETH_HLEN;
  807. skb->protocol = PKT_TYPE_LACPDU;
  808. marker_header = skb_put(skb, length);
  809. ether_addr_copy(marker_header->hdr.h_dest, lacpdu_mcast_addr);
  810. /* Note: source address is set to be the member's PERMANENT address,
  811. * because we use it to identify loopback MARKERs in receive.
  812. */
  813. ether_addr_copy(marker_header->hdr.h_source, slave->perm_hwaddr);
  814. marker_header->hdr.h_proto = PKT_TYPE_LACPDU;
  815. marker_header->marker = *marker;
  816. dev_queue_xmit(skb);
  817. return 0;
  818. }
  819. /**
  820. * ad_mux_machine - handle a port's mux state machine
  821. * @port: the port we're looking at
  822. * @update_slave_arr: Does slave array need update?
  823. */
  824. static void ad_mux_machine(struct port *port, bool *update_slave_arr)
  825. {
  826. mux_states_t last_state;
  827. /* keep current State Machine state to compare later if it was
  828. * changed
  829. */
  830. last_state = port->sm_mux_state;
  831. if (port->sm_vars & AD_PORT_BEGIN) {
  832. port->sm_mux_state = AD_MUX_DETACHED;
  833. } else {
  834. switch (port->sm_mux_state) {
  835. case AD_MUX_DETACHED:
  836. if ((port->sm_vars & AD_PORT_SELECTED)
  837. || (port->sm_vars & AD_PORT_STANDBY))
  838. /* if SELECTED or STANDBY */
  839. port->sm_mux_state = AD_MUX_WAITING;
  840. break;
  841. case AD_MUX_WAITING:
  842. /* if SELECTED == FALSE return to DETACH state */
  843. if (!(port->sm_vars & AD_PORT_SELECTED)) {
  844. port->sm_vars &= ~AD_PORT_READY_N;
  845. /* in order to withhold the Selection Logic to
  846. * check all ports READY_N value every callback
  847. * cycle to update ready variable, we check
  848. * READY_N and update READY here
  849. */
  850. __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator));
  851. port->sm_mux_state = AD_MUX_DETACHED;
  852. break;
  853. }
  854. /* check if the wait_while_timer expired */
  855. if (port->sm_mux_timer_counter
  856. && !(--port->sm_mux_timer_counter))
  857. port->sm_vars |= AD_PORT_READY_N;
  858. /* in order to withhold the selection logic to check
  859. * all ports READY_N value every callback cycle to
  860. * update ready variable, we check READY_N and update
  861. * READY here
  862. */
  863. __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator));
  864. /* if the wait_while_timer expired, and the port is
  865. * in READY state, move to ATTACHED state
  866. */
  867. if ((port->sm_vars & AD_PORT_READY)
  868. && !port->sm_mux_timer_counter)
  869. port->sm_mux_state = AD_MUX_ATTACHED;
  870. break;
  871. case AD_MUX_ATTACHED:
  872. /* check also if agg_select_timer expired (so the
  873. * edable port will take place only after this timer)
  874. */
  875. if ((port->sm_vars & AD_PORT_SELECTED) &&
  876. (port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) &&
  877. !__check_agg_selection_timer(port)) {
  878. if (port->aggregator->is_active)
  879. port->sm_mux_state =
  880. AD_MUX_COLLECTING_DISTRIBUTING;
  881. } else if (!(port->sm_vars & AD_PORT_SELECTED) ||
  882. (port->sm_vars & AD_PORT_STANDBY)) {
  883. /* if UNSELECTED or STANDBY */
  884. port->sm_vars &= ~AD_PORT_READY_N;
  885. /* in order to withhold the selection logic to
  886. * check all ports READY_N value every callback
  887. * cycle to update ready variable, we check
  888. * READY_N and update READY here
  889. */
  890. __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator));
  891. port->sm_mux_state = AD_MUX_DETACHED;
  892. } else if (port->aggregator->is_active) {
  893. port->actor_oper_port_state |=
  894. LACP_STATE_SYNCHRONIZATION;
  895. }
  896. break;
  897. case AD_MUX_COLLECTING_DISTRIBUTING:
  898. if (!(port->sm_vars & AD_PORT_SELECTED) ||
  899. (port->sm_vars & AD_PORT_STANDBY) ||
  900. !(port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) ||
  901. !(port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION)) {
  902. port->sm_mux_state = AD_MUX_ATTACHED;
  903. } else {
  904. /* if port state hasn't changed make
  905. * sure that a collecting distributing
  906. * port in an active aggregator is enabled
  907. */
  908. if (port->aggregator &&
  909. port->aggregator->is_active &&
  910. !__port_is_enabled(port)) {
  911. __enable_port(port);
  912. *update_slave_arr = true;
  913. }
  914. }
  915. break;
  916. default:
  917. break;
  918. }
  919. }
  920. /* check if the state machine was changed */
  921. if (port->sm_mux_state != last_state) {
  922. slave_dbg(port->slave->bond->dev, port->slave->dev,
  923. "Mux Machine: Port=%d, Last State=%d, Curr State=%d\n",
  924. port->actor_port_number,
  925. last_state,
  926. port->sm_mux_state);
  927. switch (port->sm_mux_state) {
  928. case AD_MUX_DETACHED:
  929. port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION;
  930. ad_disable_collecting_distributing(port,
  931. update_slave_arr);
  932. port->actor_oper_port_state &= ~LACP_STATE_COLLECTING;
  933. port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING;
  934. port->ntt = true;
  935. break;
  936. case AD_MUX_WAITING:
  937. port->sm_mux_timer_counter = __ad_timer_to_ticks(AD_WAIT_WHILE_TIMER, 0);
  938. break;
  939. case AD_MUX_ATTACHED:
  940. if (port->aggregator->is_active)
  941. port->actor_oper_port_state |=
  942. LACP_STATE_SYNCHRONIZATION;
  943. else
  944. port->actor_oper_port_state &=
  945. ~LACP_STATE_SYNCHRONIZATION;
  946. port->actor_oper_port_state &= ~LACP_STATE_COLLECTING;
  947. port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING;
  948. ad_disable_collecting_distributing(port,
  949. update_slave_arr);
  950. port->ntt = true;
  951. break;
  952. case AD_MUX_COLLECTING_DISTRIBUTING:
  953. port->actor_oper_port_state |= LACP_STATE_COLLECTING;
  954. port->actor_oper_port_state |= LACP_STATE_DISTRIBUTING;
  955. port->actor_oper_port_state |= LACP_STATE_SYNCHRONIZATION;
  956. ad_enable_collecting_distributing(port,
  957. update_slave_arr);
  958. port->ntt = true;
  959. break;
  960. default:
  961. break;
  962. }
  963. }
  964. }
  965. /**
  966. * ad_rx_machine - handle a port's rx State Machine
  967. * @lacpdu: the lacpdu we've received
  968. * @port: the port we're looking at
  969. *
  970. * If lacpdu arrived, stop previous timer (if exists) and set the next state as
  971. * CURRENT. If timer expired set the state machine in the proper state.
  972. * In other cases, this function checks if we need to switch to other state.
  973. */
  974. static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
  975. {
  976. rx_states_t last_state;
  977. /* keep current State Machine state to compare later if it was
  978. * changed
  979. */
  980. last_state = port->sm_rx_state;
  981. if (lacpdu) {
  982. atomic64_inc(&SLAVE_AD_INFO(port->slave)->stats.lacpdu_rx);
  983. atomic64_inc(&BOND_AD_INFO(port->slave->bond).stats.lacpdu_rx);
  984. }
  985. /* check if state machine should change state */
  986. /* first, check if port was reinitialized */
  987. if (port->sm_vars & AD_PORT_BEGIN) {
  988. port->sm_rx_state = AD_RX_INITIALIZE;
  989. port->sm_vars |= AD_PORT_CHURNED;
  990. /* check if port is not enabled */
  991. } else if (!(port->sm_vars & AD_PORT_BEGIN) && !port->is_enabled)
  992. port->sm_rx_state = AD_RX_PORT_DISABLED;
  993. /* check if new lacpdu arrived */
  994. else if (lacpdu && ((port->sm_rx_state == AD_RX_EXPIRED) ||
  995. (port->sm_rx_state == AD_RX_DEFAULTED) ||
  996. (port->sm_rx_state == AD_RX_CURRENT))) {
  997. if (port->sm_rx_state != AD_RX_CURRENT)
  998. port->sm_vars |= AD_PORT_CHURNED;
  999. port->sm_rx_timer_counter = 0;
  1000. port->sm_rx_state = AD_RX_CURRENT;
  1001. } else {
  1002. /* if timer is on, and if it is expired */
  1003. if (port->sm_rx_timer_counter &&
  1004. !(--port->sm_rx_timer_counter)) {
  1005. switch (port->sm_rx_state) {
  1006. case AD_RX_EXPIRED:
  1007. port->sm_rx_state = AD_RX_DEFAULTED;
  1008. break;
  1009. case AD_RX_CURRENT:
  1010. port->sm_rx_state = AD_RX_EXPIRED;
  1011. break;
  1012. default:
  1013. break;
  1014. }
  1015. } else {
  1016. /* if no lacpdu arrived and no timer is on */
  1017. switch (port->sm_rx_state) {
  1018. case AD_RX_PORT_DISABLED:
  1019. if (port->is_enabled &&
  1020. (port->sm_vars & AD_PORT_LACP_ENABLED))
  1021. port->sm_rx_state = AD_RX_EXPIRED;
  1022. else if (port->is_enabled
  1023. && ((port->sm_vars
  1024. & AD_PORT_LACP_ENABLED) == 0))
  1025. port->sm_rx_state = AD_RX_LACP_DISABLED;
  1026. break;
  1027. default:
  1028. break;
  1029. }
  1030. }
  1031. }
  1032. /* check if the State machine was changed or new lacpdu arrived */
  1033. if ((port->sm_rx_state != last_state) || (lacpdu)) {
  1034. slave_dbg(port->slave->bond->dev, port->slave->dev,
  1035. "Rx Machine: Port=%d, Last State=%d, Curr State=%d\n",
  1036. port->actor_port_number,
  1037. last_state,
  1038. port->sm_rx_state);
  1039. switch (port->sm_rx_state) {
  1040. case AD_RX_INITIALIZE:
  1041. if (!(port->actor_oper_port_key & AD_DUPLEX_KEY_MASKS))
  1042. port->sm_vars &= ~AD_PORT_LACP_ENABLED;
  1043. else
  1044. port->sm_vars |= AD_PORT_LACP_ENABLED;
  1045. port->sm_vars &= ~AD_PORT_SELECTED;
  1046. __record_default(port);
  1047. port->actor_oper_port_state &= ~LACP_STATE_EXPIRED;
  1048. port->sm_rx_state = AD_RX_PORT_DISABLED;
  1049. fallthrough;
  1050. case AD_RX_PORT_DISABLED:
  1051. port->sm_vars &= ~AD_PORT_MATCHED;
  1052. break;
  1053. case AD_RX_LACP_DISABLED:
  1054. port->sm_vars &= ~AD_PORT_SELECTED;
  1055. __record_default(port);
  1056. port->partner_oper.port_state &= ~LACP_STATE_AGGREGATION;
  1057. port->sm_vars |= AD_PORT_MATCHED;
  1058. port->actor_oper_port_state &= ~LACP_STATE_EXPIRED;
  1059. break;
  1060. case AD_RX_EXPIRED:
  1061. /* Reset of the Synchronization flag (Standard 43.4.12)
  1062. * This reset cause to disable this port in the
  1063. * COLLECTING_DISTRIBUTING state of the mux machine in
  1064. * case of EXPIRED even if LINK_DOWN didn't arrive for
  1065. * the port.
  1066. */
  1067. port->partner_oper.port_state &= ~LACP_STATE_SYNCHRONIZATION;
  1068. port->sm_vars &= ~AD_PORT_MATCHED;
  1069. port->partner_oper.port_state |= LACP_STATE_LACP_TIMEOUT;
  1070. port->partner_oper.port_state |= LACP_STATE_LACP_ACTIVITY;
  1071. port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(AD_SHORT_TIMEOUT));
  1072. port->actor_oper_port_state |= LACP_STATE_EXPIRED;
  1073. port->sm_vars |= AD_PORT_CHURNED;
  1074. break;
  1075. case AD_RX_DEFAULTED:
  1076. __update_default_selected(port);
  1077. __record_default(port);
  1078. port->sm_vars |= AD_PORT_MATCHED;
  1079. port->actor_oper_port_state &= ~LACP_STATE_EXPIRED;
  1080. break;
  1081. case AD_RX_CURRENT:
  1082. /* detect loopback situation */
  1083. if (MAC_ADDRESS_EQUAL(&(lacpdu->actor_system),
  1084. &(port->actor_system))) {
  1085. slave_err(port->slave->bond->dev, port->slave->dev, "An illegal loopback occurred on slave\n"
  1086. "Check the configuration to verify that all adapters are connected to 802.3ad compliant switch ports\n");
  1087. return;
  1088. }
  1089. __update_selected(lacpdu, port);
  1090. __update_ntt(lacpdu, port);
  1091. __record_pdu(lacpdu, port);
  1092. port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(port->actor_oper_port_state & LACP_STATE_LACP_TIMEOUT));
  1093. port->actor_oper_port_state &= ~LACP_STATE_EXPIRED;
  1094. break;
  1095. default:
  1096. break;
  1097. }
  1098. }
  1099. }
  1100. /**
  1101. * ad_churn_machine - handle port churn's state machine
  1102. * @port: the port we're looking at
  1103. *
  1104. */
  1105. static void ad_churn_machine(struct port *port)
  1106. {
  1107. if (port->sm_vars & AD_PORT_CHURNED) {
  1108. port->sm_vars &= ~AD_PORT_CHURNED;
  1109. port->sm_churn_actor_state = AD_CHURN_MONITOR;
  1110. port->sm_churn_partner_state = AD_CHURN_MONITOR;
  1111. port->sm_churn_actor_timer_counter =
  1112. __ad_timer_to_ticks(AD_ACTOR_CHURN_TIMER, 0);
  1113. port->sm_churn_partner_timer_counter =
  1114. __ad_timer_to_ticks(AD_PARTNER_CHURN_TIMER, 0);
  1115. return;
  1116. }
  1117. if (port->sm_churn_actor_timer_counter &&
  1118. !(--port->sm_churn_actor_timer_counter) &&
  1119. port->sm_churn_actor_state == AD_CHURN_MONITOR) {
  1120. if (port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION) {
  1121. port->sm_churn_actor_state = AD_NO_CHURN;
  1122. } else {
  1123. port->churn_actor_count++;
  1124. port->sm_churn_actor_state = AD_CHURN;
  1125. }
  1126. }
  1127. if (port->sm_churn_partner_timer_counter &&
  1128. !(--port->sm_churn_partner_timer_counter) &&
  1129. port->sm_churn_partner_state == AD_CHURN_MONITOR) {
  1130. if (port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) {
  1131. port->sm_churn_partner_state = AD_NO_CHURN;
  1132. } else {
  1133. port->churn_partner_count++;
  1134. port->sm_churn_partner_state = AD_CHURN;
  1135. }
  1136. }
  1137. }
  1138. /**
  1139. * ad_tx_machine - handle a port's tx state machine
  1140. * @port: the port we're looking at
  1141. */
  1142. static void ad_tx_machine(struct port *port)
  1143. {
  1144. /* check if tx timer expired, to verify that we do not send more than
  1145. * 3 packets per second
  1146. */
  1147. if (port->sm_tx_timer_counter && !(--port->sm_tx_timer_counter)) {
  1148. /* check if there is something to send */
  1149. if (port->ntt && (port->sm_vars & AD_PORT_LACP_ENABLED)) {
  1150. __update_lacpdu_from_port(port);
  1151. if (ad_lacpdu_send(port) >= 0) {
  1152. slave_dbg(port->slave->bond->dev,
  1153. port->slave->dev,
  1154. "Sent LACPDU on port %d\n",
  1155. port->actor_port_number);
  1156. /* mark ntt as false, so it will not be sent
  1157. * again until demanded
  1158. */
  1159. port->ntt = false;
  1160. }
  1161. }
  1162. /* restart tx timer(to verify that we will not exceed
  1163. * AD_MAX_TX_IN_SECOND
  1164. */
  1165. port->sm_tx_timer_counter = ad_ticks_per_sec/AD_MAX_TX_IN_SECOND;
  1166. }
  1167. }
  1168. /**
  1169. * ad_periodic_machine - handle a port's periodic state machine
  1170. * @port: the port we're looking at
  1171. * @bond_params: bond parameters we will use
  1172. *
  1173. * Turn ntt flag on priodically to perform periodic transmission of lacpdu's.
  1174. */
  1175. static void ad_periodic_machine(struct port *port, struct bond_params *bond_params)
  1176. {
  1177. periodic_states_t last_state;
  1178. /* keep current state machine state to compare later if it was changed */
  1179. last_state = port->sm_periodic_state;
  1180. /* check if port was reinitialized */
  1181. if (((port->sm_vars & AD_PORT_BEGIN) || !(port->sm_vars & AD_PORT_LACP_ENABLED) || !port->is_enabled) ||
  1182. (!(port->actor_oper_port_state & LACP_STATE_LACP_ACTIVITY) && !(port->partner_oper.port_state & LACP_STATE_LACP_ACTIVITY)) ||
  1183. !bond_params->lacp_active) {
  1184. port->sm_periodic_state = AD_NO_PERIODIC;
  1185. }
  1186. /* check if state machine should change state */
  1187. else if (port->sm_periodic_timer_counter) {
  1188. /* check if periodic state machine expired */
  1189. if (!(--port->sm_periodic_timer_counter)) {
  1190. /* if expired then do tx */
  1191. port->sm_periodic_state = AD_PERIODIC_TX;
  1192. } else {
  1193. /* If not expired, check if there is some new timeout
  1194. * parameter from the partner state
  1195. */
  1196. switch (port->sm_periodic_state) {
  1197. case AD_FAST_PERIODIC:
  1198. if (!(port->partner_oper.port_state
  1199. & LACP_STATE_LACP_TIMEOUT))
  1200. port->sm_periodic_state = AD_SLOW_PERIODIC;
  1201. break;
  1202. case AD_SLOW_PERIODIC:
  1203. if ((port->partner_oper.port_state & LACP_STATE_LACP_TIMEOUT)) {
  1204. port->sm_periodic_timer_counter = 0;
  1205. port->sm_periodic_state = AD_PERIODIC_TX;
  1206. }
  1207. break;
  1208. default:
  1209. break;
  1210. }
  1211. }
  1212. } else {
  1213. switch (port->sm_periodic_state) {
  1214. case AD_NO_PERIODIC:
  1215. port->sm_periodic_state = AD_FAST_PERIODIC;
  1216. break;
  1217. case AD_PERIODIC_TX:
  1218. if (!(port->partner_oper.port_state &
  1219. LACP_STATE_LACP_TIMEOUT))
  1220. port->sm_periodic_state = AD_SLOW_PERIODIC;
  1221. else
  1222. port->sm_periodic_state = AD_FAST_PERIODIC;
  1223. break;
  1224. default:
  1225. break;
  1226. }
  1227. }
  1228. /* check if the state machine was changed */
  1229. if (port->sm_periodic_state != last_state) {
  1230. slave_dbg(port->slave->bond->dev, port->slave->dev,
  1231. "Periodic Machine: Port=%d, Last State=%d, Curr State=%d\n",
  1232. port->actor_port_number, last_state,
  1233. port->sm_periodic_state);
  1234. switch (port->sm_periodic_state) {
  1235. case AD_NO_PERIODIC:
  1236. port->sm_periodic_timer_counter = 0;
  1237. break;
  1238. case AD_FAST_PERIODIC:
  1239. /* decrement 1 tick we lost in the PERIODIC_TX cycle */
  1240. port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_FAST_PERIODIC_TIME))-1;
  1241. break;
  1242. case AD_SLOW_PERIODIC:
  1243. /* decrement 1 tick we lost in the PERIODIC_TX cycle */
  1244. port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_SLOW_PERIODIC_TIME))-1;
  1245. break;
  1246. case AD_PERIODIC_TX:
  1247. port->ntt = true;
  1248. break;
  1249. default:
  1250. break;
  1251. }
  1252. }
  1253. }
  1254. /**
  1255. * ad_port_selection_logic - select aggregation groups
  1256. * @port: the port we're looking at
  1257. * @update_slave_arr: Does slave array need update?
  1258. *
  1259. * Select aggregation groups, and assign each port for it's aggregetor. The
  1260. * selection logic is called in the inititalization (after all the handshkes),
  1261. * and after every lacpdu receive (if selected is off).
  1262. */
  1263. static void ad_port_selection_logic(struct port *port, bool *update_slave_arr)
  1264. {
  1265. struct aggregator *aggregator, *free_aggregator = NULL, *temp_aggregator;
  1266. struct port *last_port = NULL, *curr_port;
  1267. struct list_head *iter;
  1268. struct bonding *bond;
  1269. struct slave *slave;
  1270. int found = 0;
  1271. /* if the port is already Selected, do nothing */
  1272. if (port->sm_vars & AD_PORT_SELECTED)
  1273. return;
  1274. bond = __get_bond_by_port(port);
  1275. /* if the port is connected to other aggregator, detach it */
  1276. if (port->aggregator) {
  1277. /* detach the port from its former aggregator */
  1278. temp_aggregator = port->aggregator;
  1279. for (curr_port = temp_aggregator->lag_ports; curr_port;
  1280. last_port = curr_port,
  1281. curr_port = curr_port->next_port_in_aggregator) {
  1282. if (curr_port == port) {
  1283. temp_aggregator->num_of_ports--;
  1284. /* if it is the first port attached to the
  1285. * aggregator
  1286. */
  1287. if (!last_port) {
  1288. temp_aggregator->lag_ports =
  1289. port->next_port_in_aggregator;
  1290. } else {
  1291. /* not the first port attached to the
  1292. * aggregator
  1293. */
  1294. last_port->next_port_in_aggregator =
  1295. port->next_port_in_aggregator;
  1296. }
  1297. /* clear the port's relations to this
  1298. * aggregator
  1299. */
  1300. port->aggregator = NULL;
  1301. port->next_port_in_aggregator = NULL;
  1302. port->actor_port_aggregator_identifier = 0;
  1303. slave_dbg(bond->dev, port->slave->dev, "Port %d left LAG %d\n",
  1304. port->actor_port_number,
  1305. temp_aggregator->aggregator_identifier);
  1306. /* if the aggregator is empty, clear its
  1307. * parameters, and set it ready to be attached
  1308. */
  1309. if (!temp_aggregator->lag_ports)
  1310. ad_clear_agg(temp_aggregator);
  1311. break;
  1312. }
  1313. }
  1314. if (!curr_port) {
  1315. /* meaning: the port was related to an aggregator
  1316. * but was not on the aggregator port list
  1317. */
  1318. net_warn_ratelimited("%s: (slave %s): Warning: Port %d was related to aggregator %d but was not on its port list\n",
  1319. port->slave->bond->dev->name,
  1320. port->slave->dev->name,
  1321. port->actor_port_number,
  1322. port->aggregator->aggregator_identifier);
  1323. }
  1324. }
  1325. /* search on all aggregators for a suitable aggregator for this port */
  1326. bond_for_each_slave(bond, slave, iter) {
  1327. aggregator = &(SLAVE_AD_INFO(slave)->aggregator);
  1328. /* keep a free aggregator for later use(if needed) */
  1329. if (!aggregator->lag_ports) {
  1330. if (!free_aggregator)
  1331. free_aggregator = aggregator;
  1332. continue;
  1333. }
  1334. /* check if current aggregator suits us */
  1335. if (((aggregator->actor_oper_aggregator_key == port->actor_oper_port_key) && /* if all parameters match AND */
  1336. MAC_ADDRESS_EQUAL(&(aggregator->partner_system), &(port->partner_oper.system)) &&
  1337. (aggregator->partner_system_priority == port->partner_oper.system_priority) &&
  1338. (aggregator->partner_oper_aggregator_key == port->partner_oper.key)
  1339. ) &&
  1340. ((!MAC_ADDRESS_EQUAL(&(port->partner_oper.system), &(null_mac_addr)) && /* partner answers */
  1341. !aggregator->is_individual) /* but is not individual OR */
  1342. )
  1343. ) {
  1344. /* attach to the founded aggregator */
  1345. port->aggregator = aggregator;
  1346. port->actor_port_aggregator_identifier =
  1347. port->aggregator->aggregator_identifier;
  1348. port->next_port_in_aggregator = aggregator->lag_ports;
  1349. port->aggregator->num_of_ports++;
  1350. aggregator->lag_ports = port;
  1351. slave_dbg(bond->dev, slave->dev, "Port %d joined LAG %d (existing LAG)\n",
  1352. port->actor_port_number,
  1353. port->aggregator->aggregator_identifier);
  1354. /* mark this port as selected */
  1355. port->sm_vars |= AD_PORT_SELECTED;
  1356. found = 1;
  1357. break;
  1358. }
  1359. }
  1360. /* the port couldn't find an aggregator - attach it to a new
  1361. * aggregator
  1362. */
  1363. if (!found) {
  1364. if (free_aggregator) {
  1365. /* assign port a new aggregator */
  1366. port->aggregator = free_aggregator;
  1367. port->actor_port_aggregator_identifier =
  1368. port->aggregator->aggregator_identifier;
  1369. /* update the new aggregator's parameters
  1370. * if port was responsed from the end-user
  1371. */
  1372. if (port->actor_oper_port_key & AD_DUPLEX_KEY_MASKS)
  1373. /* if port is full duplex */
  1374. port->aggregator->is_individual = false;
  1375. else
  1376. port->aggregator->is_individual = true;
  1377. port->aggregator->actor_admin_aggregator_key =
  1378. port->actor_admin_port_key;
  1379. port->aggregator->actor_oper_aggregator_key =
  1380. port->actor_oper_port_key;
  1381. port->aggregator->partner_system =
  1382. port->partner_oper.system;
  1383. port->aggregator->partner_system_priority =
  1384. port->partner_oper.system_priority;
  1385. port->aggregator->partner_oper_aggregator_key = port->partner_oper.key;
  1386. port->aggregator->receive_state = 1;
  1387. port->aggregator->transmit_state = 1;
  1388. port->aggregator->lag_ports = port;
  1389. port->aggregator->num_of_ports++;
  1390. /* mark this port as selected */
  1391. port->sm_vars |= AD_PORT_SELECTED;
  1392. slave_dbg(bond->dev, port->slave->dev, "Port %d joined LAG %d (new LAG)\n",
  1393. port->actor_port_number,
  1394. port->aggregator->aggregator_identifier);
  1395. } else {
  1396. slave_err(bond->dev, port->slave->dev,
  1397. "Port %d did not find a suitable aggregator\n",
  1398. port->actor_port_number);
  1399. return;
  1400. }
  1401. }
  1402. /* if all aggregator's ports are READY_N == TRUE, set ready=TRUE
  1403. * in all aggregator's ports, else set ready=FALSE in all
  1404. * aggregator's ports
  1405. */
  1406. __set_agg_ports_ready(port->aggregator,
  1407. __agg_ports_are_ready(port->aggregator));
  1408. aggregator = __get_first_agg(port);
  1409. ad_agg_selection_logic(aggregator, update_slave_arr);
  1410. if (!port->aggregator->is_active)
  1411. port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION;
  1412. }
  1413. /* Decide if "agg" is a better choice for the new active aggregator that
  1414. * the current best, according to the ad_select policy.
  1415. */
  1416. static struct aggregator *ad_agg_selection_test(struct aggregator *best,
  1417. struct aggregator *curr)
  1418. {
  1419. /* 0. If no best, select current.
  1420. *
  1421. * 1. If the current agg is not individual, and the best is
  1422. * individual, select current.
  1423. *
  1424. * 2. If current agg is individual and the best is not, keep best.
  1425. *
  1426. * 3. Therefore, current and best are both individual or both not
  1427. * individual, so:
  1428. *
  1429. * 3a. If current agg partner replied, and best agg partner did not,
  1430. * select current.
  1431. *
  1432. * 3b. If current agg partner did not reply and best agg partner
  1433. * did reply, keep best.
  1434. *
  1435. * 4. Therefore, current and best both have partner replies or
  1436. * both do not, so perform selection policy:
  1437. *
  1438. * BOND_AD_COUNT: Select by count of ports. If count is equal,
  1439. * select by bandwidth.
  1440. *
  1441. * BOND_AD_STABLE, BOND_AD_BANDWIDTH: Select by bandwidth.
  1442. */
  1443. if (!best)
  1444. return curr;
  1445. if (!curr->is_individual && best->is_individual)
  1446. return curr;
  1447. if (curr->is_individual && !best->is_individual)
  1448. return best;
  1449. if (__agg_has_partner(curr) && !__agg_has_partner(best))
  1450. return curr;
  1451. if (!__agg_has_partner(curr) && __agg_has_partner(best))
  1452. return best;
  1453. switch (__get_agg_selection_mode(curr->lag_ports)) {
  1454. case BOND_AD_COUNT:
  1455. if (__agg_active_ports(curr) > __agg_active_ports(best))
  1456. return curr;
  1457. if (__agg_active_ports(curr) < __agg_active_ports(best))
  1458. return best;
  1459. fallthrough;
  1460. case BOND_AD_STABLE:
  1461. case BOND_AD_BANDWIDTH:
  1462. if (__get_agg_bandwidth(curr) > __get_agg_bandwidth(best))
  1463. return curr;
  1464. break;
  1465. default:
  1466. net_warn_ratelimited("%s: (slave %s): Impossible agg select mode %d\n",
  1467. curr->slave->bond->dev->name,
  1468. curr->slave->dev->name,
  1469. __get_agg_selection_mode(curr->lag_ports));
  1470. break;
  1471. }
  1472. return best;
  1473. }
  1474. static int agg_device_up(const struct aggregator *agg)
  1475. {
  1476. struct port *port = agg->lag_ports;
  1477. if (!port)
  1478. return 0;
  1479. for (port = agg->lag_ports; port;
  1480. port = port->next_port_in_aggregator) {
  1481. if (netif_running(port->slave->dev) &&
  1482. netif_carrier_ok(port->slave->dev))
  1483. return 1;
  1484. }
  1485. return 0;
  1486. }
  1487. /**
  1488. * ad_agg_selection_logic - select an aggregation group for a team
  1489. * @agg: the aggregator we're looking at
  1490. * @update_slave_arr: Does slave array need update?
  1491. *
  1492. * It is assumed that only one aggregator may be selected for a team.
  1493. *
  1494. * The logic of this function is to select the aggregator according to
  1495. * the ad_select policy:
  1496. *
  1497. * BOND_AD_STABLE: select the aggregator with the most ports attached to
  1498. * it, and to reselect the active aggregator only if the previous
  1499. * aggregator has no more ports related to it.
  1500. *
  1501. * BOND_AD_BANDWIDTH: select the aggregator with the highest total
  1502. * bandwidth, and reselect whenever a link state change takes place or the
  1503. * set of slaves in the bond changes.
  1504. *
  1505. * BOND_AD_COUNT: select the aggregator with largest number of ports
  1506. * (slaves), and reselect whenever a link state change takes place or the
  1507. * set of slaves in the bond changes.
  1508. *
  1509. * FIXME: this function MUST be called with the first agg in the bond, or
  1510. * __get_active_agg() won't work correctly. This function should be better
  1511. * called with the bond itself, and retrieve the first agg from it.
  1512. */
  1513. static void ad_agg_selection_logic(struct aggregator *agg,
  1514. bool *update_slave_arr)
  1515. {
  1516. struct aggregator *best, *active, *origin;
  1517. struct bonding *bond = agg->slave->bond;
  1518. struct list_head *iter;
  1519. struct slave *slave;
  1520. struct port *port;
  1521. rcu_read_lock();
  1522. origin = agg;
  1523. active = __get_active_agg(agg);
  1524. best = (active && agg_device_up(active)) ? active : NULL;
  1525. bond_for_each_slave_rcu(bond, slave, iter) {
  1526. agg = &(SLAVE_AD_INFO(slave)->aggregator);
  1527. agg->is_active = 0;
  1528. if (__agg_active_ports(agg) && agg_device_up(agg))
  1529. best = ad_agg_selection_test(best, agg);
  1530. }
  1531. if (best &&
  1532. __get_agg_selection_mode(best->lag_ports) == BOND_AD_STABLE) {
  1533. /* For the STABLE policy, don't replace the old active
  1534. * aggregator if it's still active (it has an answering
  1535. * partner) or if both the best and active don't have an
  1536. * answering partner.
  1537. */
  1538. if (active && active->lag_ports &&
  1539. __agg_active_ports(active) &&
  1540. (__agg_has_partner(active) ||
  1541. (!__agg_has_partner(active) &&
  1542. !__agg_has_partner(best)))) {
  1543. if (!(!active->actor_oper_aggregator_key &&
  1544. best->actor_oper_aggregator_key)) {
  1545. best = NULL;
  1546. active->is_active = 1;
  1547. }
  1548. }
  1549. }
  1550. if (best && (best == active)) {
  1551. best = NULL;
  1552. active->is_active = 1;
  1553. }
  1554. /* if there is new best aggregator, activate it */
  1555. if (best) {
  1556. netdev_dbg(bond->dev, "(slave %s): best Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n",
  1557. best->slave ? best->slave->dev->name : "NULL",
  1558. best->aggregator_identifier, best->num_of_ports,
  1559. best->actor_oper_aggregator_key,
  1560. best->partner_oper_aggregator_key,
  1561. best->is_individual, best->is_active);
  1562. netdev_dbg(bond->dev, "(slave %s): best ports %p slave %p\n",
  1563. best->slave ? best->slave->dev->name : "NULL",
  1564. best->lag_ports, best->slave);
  1565. bond_for_each_slave_rcu(bond, slave, iter) {
  1566. agg = &(SLAVE_AD_INFO(slave)->aggregator);
  1567. slave_dbg(bond->dev, slave->dev, "Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n",
  1568. agg->aggregator_identifier, agg->num_of_ports,
  1569. agg->actor_oper_aggregator_key,
  1570. agg->partner_oper_aggregator_key,
  1571. agg->is_individual, agg->is_active);
  1572. }
  1573. /* check if any partner replies */
  1574. if (best->is_individual)
  1575. net_warn_ratelimited("%s: Warning: No 802.3ad response from the link partner for any adapters in the bond\n",
  1576. bond->dev->name);
  1577. best->is_active = 1;
  1578. netdev_dbg(bond->dev, "(slave %s): LAG %d chosen as the active LAG\n",
  1579. best->slave ? best->slave->dev->name : "NULL",
  1580. best->aggregator_identifier);
  1581. netdev_dbg(bond->dev, "(slave %s): Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n",
  1582. best->slave ? best->slave->dev->name : "NULL",
  1583. best->aggregator_identifier, best->num_of_ports,
  1584. best->actor_oper_aggregator_key,
  1585. best->partner_oper_aggregator_key,
  1586. best->is_individual, best->is_active);
  1587. /* disable the ports that were related to the former
  1588. * active_aggregator
  1589. */
  1590. if (active) {
  1591. for (port = active->lag_ports; port;
  1592. port = port->next_port_in_aggregator) {
  1593. __disable_port(port);
  1594. }
  1595. }
  1596. /* Slave array needs update. */
  1597. *update_slave_arr = true;
  1598. }
  1599. /* if the selected aggregator is of join individuals
  1600. * (partner_system is NULL), enable their ports
  1601. */
  1602. active = __get_active_agg(origin);
  1603. if (active) {
  1604. if (!__agg_has_partner(active)) {
  1605. for (port = active->lag_ports; port;
  1606. port = port->next_port_in_aggregator) {
  1607. __enable_port(port);
  1608. }
  1609. *update_slave_arr = true;
  1610. }
  1611. }
  1612. rcu_read_unlock();
  1613. bond_3ad_set_carrier(bond);
  1614. }
  1615. /**
  1616. * ad_clear_agg - clear a given aggregator's parameters
  1617. * @aggregator: the aggregator we're looking at
  1618. */
  1619. static void ad_clear_agg(struct aggregator *aggregator)
  1620. {
  1621. if (aggregator) {
  1622. aggregator->is_individual = false;
  1623. aggregator->actor_admin_aggregator_key = 0;
  1624. aggregator->actor_oper_aggregator_key = 0;
  1625. eth_zero_addr(aggregator->partner_system.mac_addr_value);
  1626. aggregator->partner_system_priority = 0;
  1627. aggregator->partner_oper_aggregator_key = 0;
  1628. aggregator->receive_state = 0;
  1629. aggregator->transmit_state = 0;
  1630. aggregator->lag_ports = NULL;
  1631. aggregator->is_active = 0;
  1632. aggregator->num_of_ports = 0;
  1633. pr_debug("%s: LAG %d was cleared\n",
  1634. aggregator->slave ?
  1635. aggregator->slave->dev->name : "NULL",
  1636. aggregator->aggregator_identifier);
  1637. }
  1638. }
  1639. /**
  1640. * ad_initialize_agg - initialize a given aggregator's parameters
  1641. * @aggregator: the aggregator we're looking at
  1642. */
  1643. static void ad_initialize_agg(struct aggregator *aggregator)
  1644. {
  1645. if (aggregator) {
  1646. ad_clear_agg(aggregator);
  1647. eth_zero_addr(aggregator->aggregator_mac_address.mac_addr_value);
  1648. aggregator->aggregator_identifier = 0;
  1649. aggregator->slave = NULL;
  1650. }
  1651. }
  1652. /**
  1653. * ad_initialize_port - initialize a given port's parameters
  1654. * @port: the port we're looking at
  1655. * @lacp_fast: boolean. whether fast periodic should be used
  1656. */
  1657. static void ad_initialize_port(struct port *port, int lacp_fast)
  1658. {
  1659. static const struct port_params tmpl = {
  1660. .system_priority = 0xffff,
  1661. .key = 1,
  1662. .port_number = 1,
  1663. .port_priority = 0xff,
  1664. .port_state = 1,
  1665. };
  1666. static const struct lacpdu lacpdu = {
  1667. .subtype = 0x01,
  1668. .version_number = 0x01,
  1669. .tlv_type_actor_info = 0x01,
  1670. .actor_information_length = 0x14,
  1671. .tlv_type_partner_info = 0x02,
  1672. .partner_information_length = 0x14,
  1673. .tlv_type_collector_info = 0x03,
  1674. .collector_information_length = 0x10,
  1675. .collector_max_delay = htons(AD_COLLECTOR_MAX_DELAY),
  1676. };
  1677. if (port) {
  1678. port->actor_port_priority = 0xff;
  1679. port->actor_port_aggregator_identifier = 0;
  1680. port->ntt = false;
  1681. port->actor_admin_port_state = LACP_STATE_AGGREGATION |
  1682. LACP_STATE_LACP_ACTIVITY;
  1683. port->actor_oper_port_state = LACP_STATE_AGGREGATION |
  1684. LACP_STATE_LACP_ACTIVITY;
  1685. if (lacp_fast)
  1686. port->actor_oper_port_state |= LACP_STATE_LACP_TIMEOUT;
  1687. memcpy(&port->partner_admin, &tmpl, sizeof(tmpl));
  1688. memcpy(&port->partner_oper, &tmpl, sizeof(tmpl));
  1689. port->is_enabled = true;
  1690. /* private parameters */
  1691. port->sm_vars = AD_PORT_BEGIN | AD_PORT_LACP_ENABLED;
  1692. port->sm_rx_state = 0;
  1693. port->sm_rx_timer_counter = 0;
  1694. port->sm_periodic_state = 0;
  1695. port->sm_periodic_timer_counter = 0;
  1696. port->sm_mux_state = 0;
  1697. port->sm_mux_timer_counter = 0;
  1698. port->sm_tx_state = 0;
  1699. port->aggregator = NULL;
  1700. port->next_port_in_aggregator = NULL;
  1701. port->transaction_id = 0;
  1702. port->sm_churn_actor_timer_counter = 0;
  1703. port->sm_churn_actor_state = 0;
  1704. port->churn_actor_count = 0;
  1705. port->sm_churn_partner_timer_counter = 0;
  1706. port->sm_churn_partner_state = 0;
  1707. port->churn_partner_count = 0;
  1708. memcpy(&port->lacpdu, &lacpdu, sizeof(lacpdu));
  1709. }
  1710. }
  1711. /**
  1712. * ad_enable_collecting_distributing - enable a port's transmit/receive
  1713. * @port: the port we're looking at
  1714. * @update_slave_arr: Does slave array need update?
  1715. *
  1716. * Enable @port if it's in an active aggregator
  1717. */
  1718. static void ad_enable_collecting_distributing(struct port *port,
  1719. bool *update_slave_arr)
  1720. {
  1721. if (port->aggregator->is_active) {
  1722. slave_dbg(port->slave->bond->dev, port->slave->dev,
  1723. "Enabling port %d (LAG %d)\n",
  1724. port->actor_port_number,
  1725. port->aggregator->aggregator_identifier);
  1726. __enable_port(port);
  1727. /* Slave array needs update */
  1728. *update_slave_arr = true;
  1729. }
  1730. }
  1731. /**
  1732. * ad_disable_collecting_distributing - disable a port's transmit/receive
  1733. * @port: the port we're looking at
  1734. * @update_slave_arr: Does slave array need update?
  1735. */
  1736. static void ad_disable_collecting_distributing(struct port *port,
  1737. bool *update_slave_arr)
  1738. {
  1739. if (port->aggregator &&
  1740. !MAC_ADDRESS_EQUAL(&(port->aggregator->partner_system),
  1741. &(null_mac_addr))) {
  1742. slave_dbg(port->slave->bond->dev, port->slave->dev,
  1743. "Disabling port %d (LAG %d)\n",
  1744. port->actor_port_number,
  1745. port->aggregator->aggregator_identifier);
  1746. __disable_port(port);
  1747. /* Slave array needs an update */
  1748. *update_slave_arr = true;
  1749. }
  1750. }
  1751. /**
  1752. * ad_marker_info_received - handle receive of a Marker information frame
  1753. * @marker_info: Marker info received
  1754. * @port: the port we're looking at
  1755. */
  1756. static void ad_marker_info_received(struct bond_marker *marker_info,
  1757. struct port *port)
  1758. {
  1759. struct bond_marker marker;
  1760. atomic64_inc(&SLAVE_AD_INFO(port->slave)->stats.marker_rx);
  1761. atomic64_inc(&BOND_AD_INFO(port->slave->bond).stats.marker_rx);
  1762. /* copy the received marker data to the response marker */
  1763. memcpy(&marker, marker_info, sizeof(struct bond_marker));
  1764. /* change the marker subtype to marker response */
  1765. marker.tlv_type = AD_MARKER_RESPONSE_SUBTYPE;
  1766. /* send the marker response */
  1767. if (ad_marker_send(port, &marker) >= 0)
  1768. slave_dbg(port->slave->bond->dev, port->slave->dev,
  1769. "Sent Marker Response on port %d\n",
  1770. port->actor_port_number);
  1771. }
  1772. /**
  1773. * ad_marker_response_received - handle receive of a marker response frame
  1774. * @marker: marker PDU received
  1775. * @port: the port we're looking at
  1776. *
  1777. * This function does nothing since we decided not to implement send and handle
  1778. * response for marker PDU's, in this stage, but only to respond to marker
  1779. * information.
  1780. */
  1781. static void ad_marker_response_received(struct bond_marker *marker,
  1782. struct port *port)
  1783. {
  1784. atomic64_inc(&SLAVE_AD_INFO(port->slave)->stats.marker_resp_rx);
  1785. atomic64_inc(&BOND_AD_INFO(port->slave->bond).stats.marker_resp_rx);
  1786. /* DO NOTHING, SINCE WE DECIDED NOT TO IMPLEMENT THIS FEATURE FOR NOW */
  1787. }
  1788. /* ========= AD exported functions to the main bonding code ========= */
  1789. /* Check aggregators status in team every T seconds */
  1790. #define AD_AGGREGATOR_SELECTION_TIMER 8
  1791. /**
  1792. * bond_3ad_initiate_agg_selection - initate aggregator selection
  1793. * @bond: bonding struct
  1794. * @timeout: timeout value to set
  1795. *
  1796. * Set the aggregation selection timer, to initiate an agg selection in
  1797. * the very near future. Called during first initialization, and during
  1798. * any down to up transitions of the bond.
  1799. */
  1800. void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout)
  1801. {
  1802. atomic_set(&BOND_AD_INFO(bond).agg_select_timer, timeout);
  1803. }
  1804. /**
  1805. * bond_3ad_initialize - initialize a bond's 802.3ad parameters and structures
  1806. * @bond: bonding struct to work on
  1807. *
  1808. * Can be called only after the mac address of the bond is set.
  1809. */
  1810. void bond_3ad_initialize(struct bonding *bond)
  1811. {
  1812. BOND_AD_INFO(bond).aggregator_identifier = 0;
  1813. BOND_AD_INFO(bond).system.sys_priority =
  1814. bond->params.ad_actor_sys_prio;
  1815. if (is_zero_ether_addr(bond->params.ad_actor_system))
  1816. BOND_AD_INFO(bond).system.sys_mac_addr =
  1817. *((struct mac_addr *)bond->dev->dev_addr);
  1818. else
  1819. BOND_AD_INFO(bond).system.sys_mac_addr =
  1820. *((struct mac_addr *)bond->params.ad_actor_system);
  1821. bond_3ad_initiate_agg_selection(bond,
  1822. AD_AGGREGATOR_SELECTION_TIMER *
  1823. ad_ticks_per_sec);
  1824. }
  1825. /**
  1826. * bond_3ad_bind_slave - initialize a slave's port
  1827. * @slave: slave struct to work on
  1828. *
  1829. * Returns: 0 on success
  1830. * < 0 on error
  1831. */
  1832. void bond_3ad_bind_slave(struct slave *slave)
  1833. {
  1834. struct bonding *bond = bond_get_bond_by_slave(slave);
  1835. struct port *port;
  1836. struct aggregator *aggregator;
  1837. /* check that the slave has not been initialized yet. */
  1838. if (SLAVE_AD_INFO(slave)->port.slave != slave) {
  1839. /* port initialization */
  1840. port = &(SLAVE_AD_INFO(slave)->port);
  1841. ad_initialize_port(port, bond->params.lacp_fast);
  1842. port->slave = slave;
  1843. port->actor_port_number = SLAVE_AD_INFO(slave)->id;
  1844. /* key is determined according to the link speed, duplex and
  1845. * user key
  1846. */
  1847. port->actor_admin_port_key = bond->params.ad_user_port_key << 6;
  1848. ad_update_actor_keys(port, false);
  1849. /* actor system is the bond's system */
  1850. __ad_actor_update_port(port);
  1851. /* tx timer(to verify that no more than MAX_TX_IN_SECOND
  1852. * lacpdu's are sent in one second)
  1853. */
  1854. port->sm_tx_timer_counter = ad_ticks_per_sec/AD_MAX_TX_IN_SECOND;
  1855. __disable_port(port);
  1856. /* aggregator initialization */
  1857. aggregator = &(SLAVE_AD_INFO(slave)->aggregator);
  1858. ad_initialize_agg(aggregator);
  1859. aggregator->aggregator_mac_address = *((struct mac_addr *)bond->dev->dev_addr);
  1860. aggregator->aggregator_identifier = ++BOND_AD_INFO(bond).aggregator_identifier;
  1861. aggregator->slave = slave;
  1862. aggregator->is_active = 0;
  1863. aggregator->num_of_ports = 0;
  1864. }
  1865. }
  1866. /**
  1867. * bond_3ad_unbind_slave - deinitialize a slave's port
  1868. * @slave: slave struct to work on
  1869. *
  1870. * Search for the aggregator that is related to this port, remove the
  1871. * aggregator and assign another aggregator for other port related to it
  1872. * (if any), and remove the port.
  1873. */
  1874. void bond_3ad_unbind_slave(struct slave *slave)
  1875. {
  1876. struct port *port, *prev_port, *temp_port;
  1877. struct aggregator *aggregator, *new_aggregator, *temp_aggregator;
  1878. int select_new_active_agg = 0;
  1879. struct bonding *bond = slave->bond;
  1880. struct slave *slave_iter;
  1881. struct list_head *iter;
  1882. bool dummy_slave_update; /* Ignore this value as caller updates array */
  1883. /* Sync against bond_3ad_state_machine_handler() */
  1884. spin_lock_bh(&bond->mode_lock);
  1885. aggregator = &(SLAVE_AD_INFO(slave)->aggregator);
  1886. port = &(SLAVE_AD_INFO(slave)->port);
  1887. /* if slave is null, the whole port is not initialized */
  1888. if (!port->slave) {
  1889. slave_warn(bond->dev, slave->dev, "Trying to unbind an uninitialized port\n");
  1890. goto out;
  1891. }
  1892. slave_dbg(bond->dev, slave->dev, "Unbinding Link Aggregation Group %d\n",
  1893. aggregator->aggregator_identifier);
  1894. /* Tell the partner that this port is not suitable for aggregation */
  1895. port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION;
  1896. port->actor_oper_port_state &= ~LACP_STATE_COLLECTING;
  1897. port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING;
  1898. port->actor_oper_port_state &= ~LACP_STATE_AGGREGATION;
  1899. __update_lacpdu_from_port(port);
  1900. ad_lacpdu_send(port);
  1901. /* check if this aggregator is occupied */
  1902. if (aggregator->lag_ports) {
  1903. /* check if there are other ports related to this aggregator
  1904. * except the port related to this slave(thats ensure us that
  1905. * there is a reason to search for new aggregator, and that we
  1906. * will find one
  1907. */
  1908. if ((aggregator->lag_ports != port) ||
  1909. (aggregator->lag_ports->next_port_in_aggregator)) {
  1910. /* find new aggregator for the related port(s) */
  1911. bond_for_each_slave(bond, slave_iter, iter) {
  1912. new_aggregator = &(SLAVE_AD_INFO(slave_iter)->aggregator);
  1913. /* if the new aggregator is empty, or it is
  1914. * connected to our port only
  1915. */
  1916. if (!new_aggregator->lag_ports ||
  1917. ((new_aggregator->lag_ports == port) &&
  1918. !new_aggregator->lag_ports->next_port_in_aggregator))
  1919. break;
  1920. }
  1921. if (!slave_iter)
  1922. new_aggregator = NULL;
  1923. /* if new aggregator found, copy the aggregator's
  1924. * parameters and connect the related lag_ports to the
  1925. * new aggregator
  1926. */
  1927. if ((new_aggregator) && ((!new_aggregator->lag_ports) || ((new_aggregator->lag_ports == port) && !new_aggregator->lag_ports->next_port_in_aggregator))) {
  1928. slave_dbg(bond->dev, slave->dev, "Some port(s) related to LAG %d - replacing with LAG %d\n",
  1929. aggregator->aggregator_identifier,
  1930. new_aggregator->aggregator_identifier);
  1931. if ((new_aggregator->lag_ports == port) &&
  1932. new_aggregator->is_active) {
  1933. slave_info(bond->dev, slave->dev, "Removing an active aggregator\n");
  1934. select_new_active_agg = 1;
  1935. }
  1936. new_aggregator->is_individual = aggregator->is_individual;
  1937. new_aggregator->actor_admin_aggregator_key = aggregator->actor_admin_aggregator_key;
  1938. new_aggregator->actor_oper_aggregator_key = aggregator->actor_oper_aggregator_key;
  1939. new_aggregator->partner_system = aggregator->partner_system;
  1940. new_aggregator->partner_system_priority = aggregator->partner_system_priority;
  1941. new_aggregator->partner_oper_aggregator_key = aggregator->partner_oper_aggregator_key;
  1942. new_aggregator->receive_state = aggregator->receive_state;
  1943. new_aggregator->transmit_state = aggregator->transmit_state;
  1944. new_aggregator->lag_ports = aggregator->lag_ports;
  1945. new_aggregator->is_active = aggregator->is_active;
  1946. new_aggregator->num_of_ports = aggregator->num_of_ports;
  1947. /* update the information that is written on
  1948. * the ports about the aggregator
  1949. */
  1950. for (temp_port = aggregator->lag_ports; temp_port;
  1951. temp_port = temp_port->next_port_in_aggregator) {
  1952. temp_port->aggregator = new_aggregator;
  1953. temp_port->actor_port_aggregator_identifier = new_aggregator->aggregator_identifier;
  1954. }
  1955. ad_clear_agg(aggregator);
  1956. if (select_new_active_agg)
  1957. ad_agg_selection_logic(__get_first_agg(port),
  1958. &dummy_slave_update);
  1959. } else {
  1960. slave_warn(bond->dev, slave->dev, "unbinding aggregator, and could not find a new aggregator for its ports\n");
  1961. }
  1962. } else {
  1963. /* in case that the only port related to this
  1964. * aggregator is the one we want to remove
  1965. */
  1966. select_new_active_agg = aggregator->is_active;
  1967. ad_clear_agg(aggregator);
  1968. if (select_new_active_agg) {
  1969. slave_info(bond->dev, slave->dev, "Removing an active aggregator\n");
  1970. /* select new active aggregator */
  1971. temp_aggregator = __get_first_agg(port);
  1972. if (temp_aggregator)
  1973. ad_agg_selection_logic(temp_aggregator,
  1974. &dummy_slave_update);
  1975. }
  1976. }
  1977. }
  1978. slave_dbg(bond->dev, slave->dev, "Unbinding port %d\n", port->actor_port_number);
  1979. /* find the aggregator that this port is connected to */
  1980. bond_for_each_slave(bond, slave_iter, iter) {
  1981. temp_aggregator = &(SLAVE_AD_INFO(slave_iter)->aggregator);
  1982. prev_port = NULL;
  1983. /* search the port in the aggregator's related ports */
  1984. for (temp_port = temp_aggregator->lag_ports; temp_port;
  1985. prev_port = temp_port,
  1986. temp_port = temp_port->next_port_in_aggregator) {
  1987. if (temp_port == port) {
  1988. /* the aggregator found - detach the port from
  1989. * this aggregator
  1990. */
  1991. if (prev_port)
  1992. prev_port->next_port_in_aggregator = temp_port->next_port_in_aggregator;
  1993. else
  1994. temp_aggregator->lag_ports = temp_port->next_port_in_aggregator;
  1995. temp_aggregator->num_of_ports--;
  1996. if (__agg_active_ports(temp_aggregator) == 0) {
  1997. select_new_active_agg = temp_aggregator->is_active;
  1998. if (temp_aggregator->num_of_ports == 0)
  1999. ad_clear_agg(temp_aggregator);
  2000. if (select_new_active_agg) {
  2001. slave_info(bond->dev, slave->dev, "Removing an active aggregator\n");
  2002. /* select new active aggregator */
  2003. ad_agg_selection_logic(__get_first_agg(port),
  2004. &dummy_slave_update);
  2005. }
  2006. }
  2007. break;
  2008. }
  2009. }
  2010. }
  2011. port->slave = NULL;
  2012. out:
  2013. spin_unlock_bh(&bond->mode_lock);
  2014. }
  2015. /**
  2016. * bond_3ad_update_ad_actor_settings - reflect change of actor settings to ports
  2017. * @bond: bonding struct to work on
  2018. *
  2019. * If an ad_actor setting gets changed we need to update the individual port
  2020. * settings so the bond device will use the new values when it gets upped.
  2021. */
  2022. void bond_3ad_update_ad_actor_settings(struct bonding *bond)
  2023. {
  2024. struct list_head *iter;
  2025. struct slave *slave;
  2026. ASSERT_RTNL();
  2027. BOND_AD_INFO(bond).system.sys_priority = bond->params.ad_actor_sys_prio;
  2028. if (is_zero_ether_addr(bond->params.ad_actor_system))
  2029. BOND_AD_INFO(bond).system.sys_mac_addr =
  2030. *((struct mac_addr *)bond->dev->dev_addr);
  2031. else
  2032. BOND_AD_INFO(bond).system.sys_mac_addr =
  2033. *((struct mac_addr *)bond->params.ad_actor_system);
  2034. spin_lock_bh(&bond->mode_lock);
  2035. bond_for_each_slave(bond, slave, iter) {
  2036. struct port *port = &(SLAVE_AD_INFO(slave))->port;
  2037. __ad_actor_update_port(port);
  2038. port->ntt = true;
  2039. }
  2040. spin_unlock_bh(&bond->mode_lock);
  2041. }
  2042. /**
  2043. * bond_agg_timer_advance - advance agg_select_timer
  2044. * @bond: bonding structure
  2045. *
  2046. * Return true when agg_select_timer reaches 0.
  2047. */
  2048. static bool bond_agg_timer_advance(struct bonding *bond)
  2049. {
  2050. int val, nval;
  2051. while (1) {
  2052. val = atomic_read(&BOND_AD_INFO(bond).agg_select_timer);
  2053. if (!val)
  2054. return false;
  2055. nval = val - 1;
  2056. if (atomic_cmpxchg(&BOND_AD_INFO(bond).agg_select_timer,
  2057. val, nval) == val)
  2058. break;
  2059. }
  2060. return nval == 0;
  2061. }
  2062. /**
  2063. * bond_3ad_state_machine_handler - handle state machines timeout
  2064. * @work: work context to fetch bonding struct to work on from
  2065. *
  2066. * The state machine handling concept in this module is to check every tick
  2067. * which state machine should operate any function. The execution order is
  2068. * round robin, so when we have an interaction between state machines, the
  2069. * reply of one to each other might be delayed until next tick.
  2070. *
  2071. * This function also complete the initialization when the agg_select_timer
  2072. * times out, and it selects an aggregator for the ports that are yet not
  2073. * related to any aggregator, and selects the active aggregator for a bond.
  2074. */
  2075. void bond_3ad_state_machine_handler(struct work_struct *work)
  2076. {
  2077. struct bonding *bond = container_of(work, struct bonding,
  2078. ad_work.work);
  2079. struct aggregator *aggregator;
  2080. struct list_head *iter;
  2081. struct slave *slave;
  2082. struct port *port;
  2083. bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER;
  2084. bool update_slave_arr = false;
  2085. /* Lock to protect data accessed by all (e.g., port->sm_vars) and
  2086. * against running with bond_3ad_unbind_slave. ad_rx_machine may run
  2087. * concurrently due to incoming LACPDU as well.
  2088. */
  2089. spin_lock_bh(&bond->mode_lock);
  2090. rcu_read_lock();
  2091. /* check if there are any slaves */
  2092. if (!bond_has_slaves(bond))
  2093. goto re_arm;
  2094. if (bond_agg_timer_advance(bond)) {
  2095. slave = bond_first_slave_rcu(bond);
  2096. port = slave ? &(SLAVE_AD_INFO(slave)->port) : NULL;
  2097. /* select the active aggregator for the bond */
  2098. if (port) {
  2099. if (!port->slave) {
  2100. net_warn_ratelimited("%s: Warning: bond's first port is uninitialized\n",
  2101. bond->dev->name);
  2102. goto re_arm;
  2103. }
  2104. aggregator = __get_first_agg(port);
  2105. ad_agg_selection_logic(aggregator, &update_slave_arr);
  2106. }
  2107. bond_3ad_set_carrier(bond);
  2108. }
  2109. /* for each port run the state machines */
  2110. bond_for_each_slave_rcu(bond, slave, iter) {
  2111. port = &(SLAVE_AD_INFO(slave)->port);
  2112. if (!port->slave) {
  2113. net_warn_ratelimited("%s: Warning: Found an uninitialized port\n",
  2114. bond->dev->name);
  2115. goto re_arm;
  2116. }
  2117. ad_rx_machine(NULL, port);
  2118. ad_periodic_machine(port, &bond->params);
  2119. ad_port_selection_logic(port, &update_slave_arr);
  2120. ad_mux_machine(port, &update_slave_arr);
  2121. ad_tx_machine(port);
  2122. ad_churn_machine(port);
  2123. /* turn off the BEGIN bit, since we already handled it */
  2124. if (port->sm_vars & AD_PORT_BEGIN)
  2125. port->sm_vars &= ~AD_PORT_BEGIN;
  2126. }
  2127. re_arm:
  2128. bond_for_each_slave_rcu(bond, slave, iter) {
  2129. if (slave->should_notify) {
  2130. should_notify_rtnl = BOND_SLAVE_NOTIFY_NOW;
  2131. break;
  2132. }
  2133. }
  2134. rcu_read_unlock();
  2135. spin_unlock_bh(&bond->mode_lock);
  2136. if (update_slave_arr)
  2137. bond_slave_arr_work_rearm(bond, 0);
  2138. if (should_notify_rtnl && rtnl_trylock()) {
  2139. bond_slave_state_notify(bond);
  2140. rtnl_unlock();
  2141. }
  2142. queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
  2143. }
  2144. /**
  2145. * bond_3ad_rx_indication - handle a received frame
  2146. * @lacpdu: received lacpdu
  2147. * @slave: slave struct to work on
  2148. *
  2149. * It is assumed that frames that were sent on this NIC don't returned as new
  2150. * received frames (loopback). Since only the payload is given to this
  2151. * function, it check for loopback.
  2152. */
  2153. static int bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave)
  2154. {
  2155. struct bonding *bond = slave->bond;
  2156. int ret = RX_HANDLER_ANOTHER;
  2157. struct bond_marker *marker;
  2158. struct port *port;
  2159. atomic64_t *stat;
  2160. port = &(SLAVE_AD_INFO(slave)->port);
  2161. if (!port->slave) {
  2162. net_warn_ratelimited("%s: Warning: port of slave %s is uninitialized\n",
  2163. slave->dev->name, slave->bond->dev->name);
  2164. return ret;
  2165. }
  2166. switch (lacpdu->subtype) {
  2167. case AD_TYPE_LACPDU:
  2168. ret = RX_HANDLER_CONSUMED;
  2169. slave_dbg(slave->bond->dev, slave->dev,
  2170. "Received LACPDU on port %d\n",
  2171. port->actor_port_number);
  2172. /* Protect against concurrent state machines */
  2173. spin_lock(&slave->bond->mode_lock);
  2174. ad_rx_machine(lacpdu, port);
  2175. spin_unlock(&slave->bond->mode_lock);
  2176. break;
  2177. case AD_TYPE_MARKER:
  2178. ret = RX_HANDLER_CONSUMED;
  2179. /* No need to convert fields to Little Endian since we
  2180. * don't use the marker's fields.
  2181. */
  2182. marker = (struct bond_marker *)lacpdu;
  2183. switch (marker->tlv_type) {
  2184. case AD_MARKER_INFORMATION_SUBTYPE:
  2185. slave_dbg(slave->bond->dev, slave->dev, "Received Marker Information on port %d\n",
  2186. port->actor_port_number);
  2187. ad_marker_info_received(marker, port);
  2188. break;
  2189. case AD_MARKER_RESPONSE_SUBTYPE:
  2190. slave_dbg(slave->bond->dev, slave->dev, "Received Marker Response on port %d\n",
  2191. port->actor_port_number);
  2192. ad_marker_response_received(marker, port);
  2193. break;
  2194. default:
  2195. slave_dbg(slave->bond->dev, slave->dev, "Received an unknown Marker subtype on port %d\n",
  2196. port->actor_port_number);
  2197. stat = &SLAVE_AD_INFO(slave)->stats.marker_unknown_rx;
  2198. atomic64_inc(stat);
  2199. stat = &BOND_AD_INFO(bond).stats.marker_unknown_rx;
  2200. atomic64_inc(stat);
  2201. }
  2202. break;
  2203. default:
  2204. atomic64_inc(&SLAVE_AD_INFO(slave)->stats.lacpdu_unknown_rx);
  2205. atomic64_inc(&BOND_AD_INFO(bond).stats.lacpdu_unknown_rx);
  2206. }
  2207. return ret;
  2208. }
  2209. /**
  2210. * ad_update_actor_keys - Update the oper / admin keys for a port based on
  2211. * its current speed and duplex settings.
  2212. *
  2213. * @port: the port we'are looking at
  2214. * @reset: Boolean to just reset the speed and the duplex part of the key
  2215. *
  2216. * The logic to change the oper / admin keys is:
  2217. * (a) A full duplex port can participate in LACP with partner.
  2218. * (b) When the speed is changed, LACP need to be reinitiated.
  2219. */
  2220. static void ad_update_actor_keys(struct port *port, bool reset)
  2221. {
  2222. u8 duplex = 0;
  2223. u16 ospeed = 0, speed = 0;
  2224. u16 old_oper_key = port->actor_oper_port_key;
  2225. port->actor_admin_port_key &= ~(AD_SPEED_KEY_MASKS|AD_DUPLEX_KEY_MASKS);
  2226. if (!reset) {
  2227. speed = __get_link_speed(port);
  2228. ospeed = (old_oper_key & AD_SPEED_KEY_MASKS) >> 1;
  2229. duplex = __get_duplex(port);
  2230. port->actor_admin_port_key |= (speed << 1) | duplex;
  2231. }
  2232. port->actor_oper_port_key = port->actor_admin_port_key;
  2233. if (old_oper_key != port->actor_oper_port_key) {
  2234. /* Only 'duplex' port participates in LACP */
  2235. if (duplex)
  2236. port->sm_vars |= AD_PORT_LACP_ENABLED;
  2237. else
  2238. port->sm_vars &= ~AD_PORT_LACP_ENABLED;
  2239. if (!reset) {
  2240. if (!speed) {
  2241. slave_err(port->slave->bond->dev,
  2242. port->slave->dev,
  2243. "speed changed to 0 on port %d\n",
  2244. port->actor_port_number);
  2245. } else if (duplex && ospeed != speed) {
  2246. /* Speed change restarts LACP state-machine */
  2247. port->sm_vars |= AD_PORT_BEGIN;
  2248. }
  2249. }
  2250. }
  2251. }
  2252. /**
  2253. * bond_3ad_adapter_speed_duplex_changed - handle a slave's speed / duplex
  2254. * change indication
  2255. *
  2256. * @slave: slave struct to work on
  2257. *
  2258. * Handle reselection of aggregator (if needed) for this port.
  2259. */
  2260. void bond_3ad_adapter_speed_duplex_changed(struct slave *slave)
  2261. {
  2262. struct port *port;
  2263. port = &(SLAVE_AD_INFO(slave)->port);
  2264. /* if slave is null, the whole port is not initialized */
  2265. if (!port->slave) {
  2266. slave_warn(slave->bond->dev, slave->dev,
  2267. "speed/duplex changed for uninitialized port\n");
  2268. return;
  2269. }
  2270. spin_lock_bh(&slave->bond->mode_lock);
  2271. ad_update_actor_keys(port, false);
  2272. spin_unlock_bh(&slave->bond->mode_lock);
  2273. slave_dbg(slave->bond->dev, slave->dev, "Port %d changed speed/duplex\n",
  2274. port->actor_port_number);
  2275. }
  2276. /**
  2277. * bond_3ad_handle_link_change - handle a slave's link status change indication
  2278. * @slave: slave struct to work on
  2279. * @link: whether the link is now up or down
  2280. *
  2281. * Handle reselection of aggregator (if needed) for this port.
  2282. */
  2283. void bond_3ad_handle_link_change(struct slave *slave, char link)
  2284. {
  2285. struct aggregator *agg;
  2286. struct port *port;
  2287. bool dummy;
  2288. port = &(SLAVE_AD_INFO(slave)->port);
  2289. /* if slave is null, the whole port is not initialized */
  2290. if (!port->slave) {
  2291. slave_warn(slave->bond->dev, slave->dev, "link status changed for uninitialized port\n");
  2292. return;
  2293. }
  2294. spin_lock_bh(&slave->bond->mode_lock);
  2295. /* on link down we are zeroing duplex and speed since
  2296. * some of the adaptors(ce1000.lan) report full duplex/speed
  2297. * instead of N/A(duplex) / 0(speed).
  2298. *
  2299. * on link up we are forcing recheck on the duplex and speed since
  2300. * some of he adaptors(ce1000.lan) report.
  2301. */
  2302. if (link == BOND_LINK_UP) {
  2303. port->is_enabled = true;
  2304. ad_update_actor_keys(port, false);
  2305. } else {
  2306. /* link has failed */
  2307. port->is_enabled = false;
  2308. ad_update_actor_keys(port, true);
  2309. }
  2310. agg = __get_first_agg(port);
  2311. ad_agg_selection_logic(agg, &dummy);
  2312. spin_unlock_bh(&slave->bond->mode_lock);
  2313. slave_dbg(slave->bond->dev, slave->dev, "Port %d changed link status to %s\n",
  2314. port->actor_port_number,
  2315. link == BOND_LINK_UP ? "UP" : "DOWN");
  2316. /* RTNL is held and mode_lock is released so it's safe
  2317. * to update slave_array here.
  2318. */
  2319. bond_update_slave_arr(slave->bond, NULL);
  2320. }
  2321. /**
  2322. * bond_3ad_set_carrier - set link state for bonding master
  2323. * @bond: bonding structure
  2324. *
  2325. * if we have an active aggregator, we're up, if not, we're down.
  2326. * Presumes that we cannot have an active aggregator if there are
  2327. * no slaves with link up.
  2328. *
  2329. * This behavior complies with IEEE 802.3 section 43.3.9.
  2330. *
  2331. * Called by bond_set_carrier(). Return zero if carrier state does not
  2332. * change, nonzero if it does.
  2333. */
  2334. int bond_3ad_set_carrier(struct bonding *bond)
  2335. {
  2336. struct aggregator *active;
  2337. struct slave *first_slave;
  2338. int ret = 1;
  2339. rcu_read_lock();
  2340. first_slave = bond_first_slave_rcu(bond);
  2341. if (!first_slave) {
  2342. ret = 0;
  2343. goto out;
  2344. }
  2345. active = __get_active_agg(&(SLAVE_AD_INFO(first_slave)->aggregator));
  2346. if (active) {
  2347. /* are enough slaves available to consider link up? */
  2348. if (__agg_active_ports(active) < bond->params.min_links) {
  2349. if (netif_carrier_ok(bond->dev)) {
  2350. netif_carrier_off(bond->dev);
  2351. goto out;
  2352. }
  2353. } else if (!netif_carrier_ok(bond->dev)) {
  2354. netif_carrier_on(bond->dev);
  2355. goto out;
  2356. }
  2357. } else if (netif_carrier_ok(bond->dev)) {
  2358. netif_carrier_off(bond->dev);
  2359. }
  2360. out:
  2361. rcu_read_unlock();
  2362. return ret;
  2363. }
  2364. /**
  2365. * __bond_3ad_get_active_agg_info - get information of the active aggregator
  2366. * @bond: bonding struct to work on
  2367. * @ad_info: ad_info struct to fill with the bond's info
  2368. *
  2369. * Returns: 0 on success
  2370. * < 0 on error
  2371. */
  2372. int __bond_3ad_get_active_agg_info(struct bonding *bond,
  2373. struct ad_info *ad_info)
  2374. {
  2375. struct aggregator *aggregator = NULL;
  2376. struct list_head *iter;
  2377. struct slave *slave;
  2378. struct port *port;
  2379. bond_for_each_slave_rcu(bond, slave, iter) {
  2380. port = &(SLAVE_AD_INFO(slave)->port);
  2381. if (port->aggregator && port->aggregator->is_active) {
  2382. aggregator = port->aggregator;
  2383. break;
  2384. }
  2385. }
  2386. if (!aggregator)
  2387. return -1;
  2388. ad_info->aggregator_id = aggregator->aggregator_identifier;
  2389. ad_info->ports = __agg_active_ports(aggregator);
  2390. ad_info->actor_key = aggregator->actor_oper_aggregator_key;
  2391. ad_info->partner_key = aggregator->partner_oper_aggregator_key;
  2392. ether_addr_copy(ad_info->partner_system,
  2393. aggregator->partner_system.mac_addr_value);
  2394. return 0;
  2395. }
  2396. int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info)
  2397. {
  2398. int ret;
  2399. rcu_read_lock();
  2400. ret = __bond_3ad_get_active_agg_info(bond, ad_info);
  2401. rcu_read_unlock();
  2402. return ret;
  2403. }
  2404. int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
  2405. struct slave *slave)
  2406. {
  2407. struct lacpdu *lacpdu, _lacpdu;
  2408. if (skb->protocol != PKT_TYPE_LACPDU)
  2409. return RX_HANDLER_ANOTHER;
  2410. if (!MAC_ADDRESS_EQUAL(eth_hdr(skb)->h_dest, lacpdu_mcast_addr))
  2411. return RX_HANDLER_ANOTHER;
  2412. lacpdu = skb_header_pointer(skb, 0, sizeof(_lacpdu), &_lacpdu);
  2413. if (!lacpdu) {
  2414. atomic64_inc(&SLAVE_AD_INFO(slave)->stats.lacpdu_illegal_rx);
  2415. atomic64_inc(&BOND_AD_INFO(bond).stats.lacpdu_illegal_rx);
  2416. return RX_HANDLER_ANOTHER;
  2417. }
  2418. return bond_3ad_rx_indication(lacpdu, slave);
  2419. }
  2420. /**
  2421. * bond_3ad_update_lacp_rate - change the lacp rate
  2422. * @bond: bonding struct
  2423. *
  2424. * When modify lacp_rate parameter via sysfs,
  2425. * update actor_oper_port_state of each port.
  2426. *
  2427. * Hold bond->mode_lock,
  2428. * so we can modify port->actor_oper_port_state,
  2429. * no matter bond is up or down.
  2430. */
  2431. void bond_3ad_update_lacp_rate(struct bonding *bond)
  2432. {
  2433. struct port *port = NULL;
  2434. struct list_head *iter;
  2435. struct slave *slave;
  2436. int lacp_fast;
  2437. lacp_fast = bond->params.lacp_fast;
  2438. spin_lock_bh(&bond->mode_lock);
  2439. bond_for_each_slave(bond, slave, iter) {
  2440. port = &(SLAVE_AD_INFO(slave)->port);
  2441. if (lacp_fast)
  2442. port->actor_oper_port_state |= LACP_STATE_LACP_TIMEOUT;
  2443. else
  2444. port->actor_oper_port_state &= ~LACP_STATE_LACP_TIMEOUT;
  2445. }
  2446. spin_unlock_bh(&bond->mode_lock);
  2447. }
  2448. size_t bond_3ad_stats_size(void)
  2449. {
  2450. return nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_RX */
  2451. nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_TX */
  2452. nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_UNKNOWN_RX */
  2453. nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_ILLEGAL_RX */
  2454. nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_RX */
  2455. nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_TX */
  2456. nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_RESP_RX */
  2457. nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_RESP_TX */
  2458. nla_total_size_64bit(sizeof(u64)); /* BOND_3AD_STAT_MARKER_UNKNOWN_RX */
  2459. }
  2460. int bond_3ad_stats_fill(struct sk_buff *skb, struct bond_3ad_stats *stats)
  2461. {
  2462. u64 val;
  2463. val = atomic64_read(&stats->lacpdu_rx);
  2464. if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_RX, val,
  2465. BOND_3AD_STAT_PAD))
  2466. return -EMSGSIZE;
  2467. val = atomic64_read(&stats->lacpdu_tx);
  2468. if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_TX, val,
  2469. BOND_3AD_STAT_PAD))
  2470. return -EMSGSIZE;
  2471. val = atomic64_read(&stats->lacpdu_unknown_rx);
  2472. if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_UNKNOWN_RX, val,
  2473. BOND_3AD_STAT_PAD))
  2474. return -EMSGSIZE;
  2475. val = atomic64_read(&stats->lacpdu_illegal_rx);
  2476. if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_ILLEGAL_RX, val,
  2477. BOND_3AD_STAT_PAD))
  2478. return -EMSGSIZE;
  2479. val = atomic64_read(&stats->marker_rx);
  2480. if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_RX, val,
  2481. BOND_3AD_STAT_PAD))
  2482. return -EMSGSIZE;
  2483. val = atomic64_read(&stats->marker_tx);
  2484. if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_TX, val,
  2485. BOND_3AD_STAT_PAD))
  2486. return -EMSGSIZE;
  2487. val = atomic64_read(&stats->marker_resp_rx);
  2488. if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_RESP_RX, val,
  2489. BOND_3AD_STAT_PAD))
  2490. return -EMSGSIZE;
  2491. val = atomic64_read(&stats->marker_resp_tx);
  2492. if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_RESP_TX, val,
  2493. BOND_3AD_STAT_PAD))
  2494. return -EMSGSIZE;
  2495. val = atomic64_read(&stats->marker_unknown_rx);
  2496. if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_UNKNOWN_RX, val,
  2497. BOND_3AD_STAT_PAD))
  2498. return -EMSGSIZE;
  2499. return 0;
  2500. }