You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xsigo.c 50KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. /*
  2. * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <errno.h>
  27. #include <byteswap.h>
  28. #include <ipxe/version.h>
  29. #include <ipxe/timer.h>
  30. #include <ipxe/malloc.h>
  31. #include <ipxe/iobuf.h>
  32. #include <ipxe/retry.h>
  33. #include <ipxe/process.h>
  34. #include <ipxe/settings.h>
  35. #include <ipxe/infiniband.h>
  36. #include <ipxe/ib_service.h>
  37. #include <ipxe/ib_cmrc.h>
  38. #include <ipxe/if_ether.h>
  39. #include <ipxe/ethernet.h>
  40. #include <ipxe/eoib.h>
  41. #include <ipxe/xsigo.h>
  42. /** @file
  43. *
  44. * Xsigo virtual Ethernet devices
  45. *
  46. */
  47. /** A Xsigo device */
  48. struct xsigo_device {
  49. /** Reference count */
  50. struct refcnt refcnt;
  51. /** Underlying Infiniband device */
  52. struct ib_device *ibdev;
  53. /** List of Xsigo devices */
  54. struct list_head list;
  55. /** Device name */
  56. const char *name;
  57. /** Link opener timer */
  58. struct retry_timer opener;
  59. /** Discovery timer */
  60. struct retry_timer discovery;
  61. /** Discovery management transaction (if any) */
  62. struct ib_mad_transaction *madx;
  63. /** List of configuration managers */
  64. struct list_head managers;
  65. };
  66. /** A Xsigo configuration manager */
  67. struct xsigo_manager {
  68. /** Reference count */
  69. struct refcnt refcnt;
  70. /** Xsigo device */
  71. struct xsigo_device *xdev;
  72. /** List of managers */
  73. struct list_head list;
  74. /** Device name */
  75. char name[16];
  76. /** Manager ID */
  77. struct xsigo_manager_id id;
  78. /** Data transfer interface */
  79. struct interface xfer;
  80. /** Connection timer */
  81. struct retry_timer reopen;
  82. /** Keepalive timer */
  83. struct retry_timer keepalive;
  84. /** Transmission process */
  85. struct process process;
  86. /** Pending transmissions */
  87. unsigned int pending;
  88. /** Transmit sequence number */
  89. uint32_t seq;
  90. /** List of virtual Ethernet devices */
  91. struct list_head nics;
  92. };
  93. /** Configuration manager pending transmissions */
  94. enum xsigo_manager_pending {
  95. /** Send connection request */
  96. XCM_TX_CONNECT = 0x0001,
  97. /** Send registration message */
  98. XCM_TX_REGISTER = 0x0002,
  99. };
  100. /** A Xsigo virtual Ethernet device */
  101. struct xsigo_nic {
  102. /** Configuration manager */
  103. struct xsigo_manager *xcm;
  104. /** List of virtual Ethernet devices */
  105. struct list_head list;
  106. /** Device name */
  107. char name[16];
  108. /** Resource identifier */
  109. union ib_guid resource;
  110. /** MAC address */
  111. uint8_t mac[ETH_ALEN];
  112. /** Network ID */
  113. unsigned long network;
  114. };
  115. /** Configuration manager service ID */
  116. static union ib_guid xcm_service_id = {
  117. .bytes = XCM_SERVICE_ID,
  118. };
  119. /** List of all Xsigo devices */
  120. static LIST_HEAD ( xsigo_devices );
  121. /**
  122. * Free Xsigo device
  123. *
  124. * @v refcnt Reference count
  125. */
  126. static void xsigo_free ( struct refcnt *refcnt ) {
  127. struct xsigo_device *xdev =
  128. container_of ( refcnt, struct xsigo_device, refcnt );
  129. /* Sanity checks */
  130. assert ( ! timer_running ( &xdev->opener ) );
  131. assert ( ! timer_running ( &xdev->discovery ) );
  132. assert ( xdev->madx == NULL );
  133. assert ( list_empty ( &xdev->managers ) );
  134. /* Drop reference to Infiniband device */
  135. ibdev_put ( xdev->ibdev );
  136. /* Free device */
  137. free ( xdev );
  138. }
  139. /**
  140. * Free configuration manager
  141. *
  142. * @v refcnt Reference count
  143. */
  144. static void xcm_free ( struct refcnt *refcnt ) {
  145. struct xsigo_manager *xcm =
  146. container_of ( refcnt, struct xsigo_manager, refcnt );
  147. /* Sanity checks */
  148. assert ( ! timer_running ( &xcm->reopen ) );
  149. assert ( ! timer_running ( &xcm->keepalive ) );
  150. assert ( ! process_running ( &xcm->process ) );
  151. assert ( list_empty ( &xcm->nics ) );
  152. /* Drop reference to Xsigo device */
  153. ref_put ( &xcm->xdev->refcnt );
  154. /* Free manager */
  155. free ( xcm );
  156. }
  157. /****************************************************************************
  158. *
  159. * Virtual Ethernet (XVE) devices
  160. *
  161. ****************************************************************************
  162. */
  163. /**
  164. * Create virtual Ethernet device
  165. *
  166. * @v xcm Configuration manager
  167. * @v resource Resource identifier
  168. * @v mac Ethernet MAC
  169. * @v network Network identifier
  170. * @v name Device name
  171. * @ret rc Return status code
  172. */
  173. static int xve_create ( struct xsigo_manager *xcm, union ib_guid *resource,
  174. const uint8_t *mac, unsigned long network,
  175. unsigned long qkey, const char *name ) {
  176. struct xsigo_device *xdev = xcm->xdev;
  177. struct ib_device *ibdev = xdev->ibdev;
  178. struct xsigo_nic *xve;
  179. struct ib_address_vector broadcast;
  180. int rc;
  181. /* Allocate and initialise structure */
  182. xve = zalloc ( sizeof ( *xve ) );
  183. if ( ! xve ) {
  184. rc = -ENOMEM;
  185. goto err_alloc;
  186. }
  187. xve->xcm = xcm;
  188. snprintf ( xve->name, sizeof ( xve->name ), "%s", name );
  189. memcpy ( &xve->resource, resource, sizeof ( xve->resource ) );
  190. memcpy ( xve->mac, mac, ETH_ALEN );
  191. xve->network = network;
  192. DBGC ( xve, "XVE %s created for %s " IB_GUID_FMT "\n",
  193. xve->name, xcm->name, IB_GUID_ARGS ( resource ) );
  194. DBGC ( xve, "XVE %s is MAC %s on network %ld\n",
  195. xve->name, eth_ntoa ( mac ), network );
  196. /* Construct broadcast address vector */
  197. memset ( &broadcast, 0, sizeof ( broadcast ) );
  198. broadcast.qpn = IB_QPN_BROADCAST;
  199. broadcast.qkey = qkey;
  200. broadcast.gid_present = 1;
  201. broadcast.gid.dwords[0] = htonl ( XVE_PREFIX );
  202. broadcast.gid.words[2] = htons ( ibdev->pkey );
  203. broadcast.gid.dwords[3] = htonl ( network );
  204. /* Create EoIB device */
  205. if ( ( rc = eoib_create ( ibdev, xve->mac, &broadcast,
  206. xve->name ) ) != 0 ) {
  207. DBGC ( xve, "XVE %s could not create EoIB device: %s\n",
  208. xve->name, strerror ( rc ) );
  209. goto err_create;
  210. }
  211. /* Add to list of virtual Ethernet devices. Do this only
  212. * after creating the EoIB device, so that our net device
  213. * notifier won't attempt to send an operational state update
  214. * before we have acknowledged the installation.
  215. */
  216. list_add ( &xve->list, &xcm->nics );
  217. return 0;
  218. list_del ( &xve->list );
  219. err_create:
  220. free ( xve );
  221. err_alloc:
  222. return rc;
  223. }
  224. /**
  225. * Find virtual Ethernet device
  226. *
  227. * @v xcm Configuration manager
  228. * @v resource Resource identifier
  229. * @ret xve Virtual Ethernet device, or NULL
  230. */
  231. static struct xsigo_nic * xve_find ( struct xsigo_manager *xcm,
  232. union ib_guid *resource ) {
  233. struct xsigo_nic *xve;
  234. list_for_each_entry ( xve, &xcm->nics, list ) {
  235. if ( memcmp ( resource, &xve->resource,
  236. sizeof ( *resource ) ) == 0 )
  237. return xve;
  238. }
  239. return NULL;
  240. }
  241. /**
  242. * Destroy virtual Ethernet device
  243. *
  244. * @v xve Virtual Ethernet device
  245. */
  246. static void xve_destroy ( struct xsigo_nic *xve ) {
  247. struct xsigo_manager *xcm = xve->xcm;
  248. struct xsigo_device *xdev = xcm->xdev;
  249. struct ib_device *ibdev = xdev->ibdev;
  250. struct eoib_device *eoib;
  251. /* Destroy corresponding EoIB device, if any */
  252. if ( ( eoib = eoib_find ( ibdev, xve->mac ) ) )
  253. eoib_destroy ( eoib );
  254. /* Remove from list of virtual Ethernet devices */
  255. list_del ( &xve->list );
  256. /* Free virtual Ethernet device */
  257. DBGC ( xve, "XVE %s destroyed\n", xve->name );
  258. free ( xve );
  259. }
  260. /**
  261. * Update virtual Ethernet device MTU
  262. *
  263. * @v xve Virtual Ethernet device
  264. * @v eoib EoIB device
  265. * @v mtu New MTU (excluding Ethernet and EoIB headers)
  266. * @ret rc Return status code
  267. */
  268. static int xve_update_mtu ( struct xsigo_nic *xve, struct eoib_device *eoib,
  269. size_t mtu ) {
  270. struct net_device *netdev = eoib->netdev;
  271. size_t max;
  272. /* Check that we can support this MTU */
  273. max = ( IB_MAX_PAYLOAD_SIZE - ( sizeof ( struct ethhdr ) +
  274. sizeof ( struct eoib_header ) ) );
  275. if ( mtu > max ) {
  276. DBGC ( xve, "XVE %s cannot support MTU %zd (max %zd)\n",
  277. xve->name, mtu, max );
  278. return -ERANGE;
  279. }
  280. /* Update MTU. No need to close/reopen the network device,
  281. * since our Infiniband stack uses a fixed MTU anyway. Note
  282. * that the network device sees the Ethernet frame header but
  283. * not the EoIB header.
  284. */
  285. netdev->max_pkt_len = ( mtu + sizeof ( struct ethhdr ) );
  286. DBGC ( xve, "XVE %s has MTU %zd\n", xve->name, mtu );
  287. return 0;
  288. }
  289. /**
  290. * Open virtual Ethernet device
  291. *
  292. * @v xve Virtual Ethernet device
  293. * @v eoib EoIB device
  294. * @v open New administrative state
  295. * @ret rc Return status code
  296. */
  297. static int xve_open ( struct xsigo_nic *xve, struct eoib_device *eoib ) {
  298. struct net_device *netdev = eoib->netdev;
  299. int rc;
  300. /* Do nothing if network device is already open */
  301. if ( netdev_is_open ( netdev ) )
  302. return 0;
  303. DBGC ( xve, "XVE %s opening network device\n", xve->name );
  304. /* Open network device */
  305. if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
  306. DBGC ( xve, "XVE %s could not open: %s\n",
  307. xve->name, strerror ( rc ) );
  308. return rc;
  309. }
  310. return 0;
  311. }
  312. /**
  313. * Close virtual Ethernet device
  314. *
  315. * @v xve Virtual Ethernet device
  316. * @v eoib EoIB device
  317. */
  318. static void xve_close ( struct xsigo_nic *xve, struct eoib_device *eoib ) {
  319. struct net_device *netdev = eoib->netdev;
  320. /* Do nothing if network device is already closed */
  321. if ( ! netdev_is_open ( netdev ) )
  322. return;
  323. /* Close network device */
  324. netdev_close ( netdev );
  325. DBGC ( xve, "XVE %s closed network device\n", xve->name );
  326. }
  327. /**
  328. * Update virtual Ethernet device administrative state
  329. *
  330. * @v xve Virtual Ethernet device
  331. * @v eoib EoIB device
  332. * @v open New administrative state
  333. * @ret rc Return status code
  334. */
  335. static int xve_update_state ( struct xsigo_nic *xve, struct eoib_device *eoib,
  336. int open ) {
  337. /* Open or close device, as applicable */
  338. if ( open ) {
  339. return xve_open ( xve, eoib );
  340. } else {
  341. xve_close ( xve, eoib );
  342. return 0;
  343. }
  344. }
  345. /**
  346. * Update gateway (TCA)
  347. *
  348. * @v xve Virtual Ethernet device
  349. * @v eoib EoIB device
  350. * @v av Address vector, or NULL if no gateway
  351. * @ret rc Return status code
  352. */
  353. static int xve_update_tca ( struct xsigo_nic *xve, struct eoib_device *eoib,
  354. struct ib_address_vector *av ) {
  355. /* Update gateway address */
  356. eoib_set_gateway ( eoib, av );
  357. if ( av ) {
  358. DBGC ( xve, "XVE %s has TCA " IB_GID_FMT " data %#lx qkey "
  359. "%#lx\n", xve->name, IB_GID_ARGS ( &av->gid ), av->qpn,
  360. av->qkey );
  361. } else {
  362. DBGC ( xve, "XVE %s has no TCA\n", xve->name );
  363. }
  364. /* The Linux driver will modify the local device's link state
  365. * to reflect the EoIB-to-Ethernet gateway's link state, but
  366. * this seems philosophically incorrect since communication
  367. * within the EoIB broadcast domain still works regardless of
  368. * the state of the gateway.
  369. */
  370. return 0;
  371. }
  372. /****************************************************************************
  373. *
  374. * Server management protocol (XSMP) session messages
  375. *
  376. ****************************************************************************
  377. */
  378. /**
  379. * Get session message name (for debugging)
  380. *
  381. * @v type Message type
  382. * @ret name Message name
  383. */
  384. static const char * xsmp_session_type ( unsigned int type ) {
  385. static char buf[16];
  386. switch ( type ) {
  387. case XSMP_SESSION_TYPE_HELLO: return "HELLO";
  388. case XSMP_SESSION_TYPE_REGISTER: return "REGISTER";
  389. case XSMP_SESSION_TYPE_CONFIRM: return "CONFIRM";
  390. case XSMP_SESSION_TYPE_REJECT: return "REJECT";
  391. case XSMP_SESSION_TYPE_SHUTDOWN: return "SHUTDOWN";
  392. default:
  393. snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", type );
  394. return buf;
  395. }
  396. }
  397. /**
  398. * Extract chassis name (for debugging)
  399. *
  400. * @v msg Session message
  401. * @ret chassis Chassis name
  402. */
  403. static const char * xsmp_chassis_name ( struct xsmp_session_message *msg ) {
  404. static char chassis[ sizeof ( msg->chassis ) + 1 /* NUL */ ];
  405. memcpy ( chassis, msg->chassis, sizeof ( msg->chassis ) );
  406. return chassis;
  407. }
  408. /**
  409. * Extract session name (for debugging)
  410. *
  411. * @v msg Session message
  412. * @ret session Session name
  413. */
  414. static const char * xsmp_session_name ( struct xsmp_session_message *msg ) {
  415. static char session[ sizeof ( msg->session ) + 1 /* NUL */ ];
  416. memcpy ( session, msg->session, sizeof ( msg->session ) );
  417. return session;
  418. }
  419. /**
  420. * Send session message
  421. *
  422. * @v xcm Configuration manager
  423. * @v type Message type
  424. * @ret rc Return status code
  425. */
  426. static int xsmp_tx_session ( struct xsigo_manager *xcm, unsigned int type ) {
  427. struct xsigo_device *xdev = xcm->xdev;
  428. struct ib_device *ibdev = xdev->ibdev;
  429. struct xsmp_session_message msg;
  430. int rc;
  431. /* Construct session message */
  432. memset ( &msg, 0, sizeof ( msg ) );
  433. msg.hdr.type = XSMP_TYPE_SESSION;
  434. msg.hdr.len = htons ( sizeof ( msg ) );
  435. msg.hdr.seq = htonl ( ++xcm->seq );
  436. memcpy ( &msg.hdr.src.guid, &ibdev->gid.s.guid,
  437. sizeof ( msg.hdr.src.guid ) );
  438. memcpy ( &msg.hdr.dst.guid, &xcm->id.guid,
  439. sizeof ( msg.hdr.dst.guid ) );
  440. msg.type = type;
  441. msg.len = htons ( sizeof ( msg ) - sizeof ( msg.hdr ) );
  442. msg.os_type = XSIGO_OS_TYPE_GENERIC;
  443. msg.resources = htons ( XSIGO_RESOURCE_XVE |
  444. XSIGO_RESOURCE_NO_HA );
  445. msg.boot = htonl ( XSMP_BOOT_PXE );
  446. DBGCP ( xcm, "XCM %s TX[%d] session %s\n", xcm->name,
  447. ntohl ( msg.hdr.seq ), xsmp_session_type ( msg.type ) );
  448. DBGCP_HDA ( xcm, 0, &msg, sizeof ( msg ) );
  449. /* Send session message */
  450. if ( ( rc = xfer_deliver_raw ( &xcm->xfer, &msg,
  451. sizeof ( msg ) ) ) != 0 ) {
  452. DBGC ( xcm, "XCM %s TX session %s failed: %s\n", xcm->name,
  453. xsmp_session_type ( msg.type ), strerror ( rc ) );
  454. return rc;
  455. }
  456. return 0;
  457. }
  458. /**
  459. * Send registration message
  460. *
  461. * @v xcm Configuration manager
  462. * @ret rc Return status code
  463. */
  464. static inline int xsmp_tx_session_register ( struct xsigo_manager *xcm ) {
  465. DBGC ( xcm, "XCM %s registering with " IB_GUID_FMT "\n",
  466. xcm->name, IB_GUID_ARGS ( &xcm->id.guid ) );
  467. /* Send registration message */
  468. return xsmp_tx_session ( xcm, XSMP_SESSION_TYPE_REGISTER );
  469. }
  470. /**
  471. * Send keepalive message
  472. *
  473. * @v xcm Configuration manager
  474. * @ret rc Return status code
  475. */
  476. static int xsmp_tx_session_hello ( struct xsigo_manager *xcm ) {
  477. /* Send keepalive message */
  478. return xsmp_tx_session ( xcm, XSMP_SESSION_TYPE_HELLO );
  479. }
  480. /**
  481. * Handle received keepalive message
  482. *
  483. * @v xcm Configuration manager
  484. * @v msg Keepalive message
  485. * @ret rc Return status code
  486. */
  487. static int xsmp_rx_session_hello ( struct xsigo_manager *xcm,
  488. struct xsmp_session_message *msg __unused ) {
  489. /* Respond to keepalive message. Note that the XCM doesn't
  490. * seem to actually ever send these.
  491. */
  492. return xsmp_tx_session_hello ( xcm );
  493. }
  494. /**
  495. * Handle received registration confirmation message
  496. *
  497. * @v xcm Configuration manager
  498. * @v msg Registration confirmation message
  499. * @ret rc Return status code
  500. */
  501. static int xsmp_rx_session_confirm ( struct xsigo_manager *xcm,
  502. struct xsmp_session_message *msg ) {
  503. DBGC ( xcm, "XCM %s registered with \"%s\" as \"%s\"\n", xcm->name,
  504. xsmp_chassis_name ( msg ), xsmp_session_name ( msg ) );
  505. return 0;
  506. }
  507. /**
  508. * Handle received registration rejection message
  509. *
  510. * @v xcm Configuration manager
  511. * @v msg Registration confirmation message
  512. * @ret rc Return status code
  513. */
  514. static int xsmp_rx_session_reject ( struct xsigo_manager *xcm,
  515. struct xsmp_session_message *msg ) {
  516. DBGC ( xcm, "XCM %s rejected by \"%s\":\n",
  517. xcm->name, xsmp_chassis_name ( msg ) );
  518. DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) );
  519. return -EPERM;
  520. }
  521. /**
  522. * Handle received shutdown message
  523. *
  524. * @v xcm Configuration manager
  525. * @v msg Registration confirmation message
  526. * @ret rc Return status code
  527. */
  528. static int xsmp_rx_session_shutdown ( struct xsigo_manager *xcm,
  529. struct xsmp_session_message *msg ) {
  530. DBGC ( xcm, "XCM %s shut down by \"%s\":\n",
  531. xcm->name, xsmp_chassis_name ( msg ) );
  532. DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) );
  533. return -ENOTCONN;
  534. }
  535. /**
  536. * Handle received session message
  537. *
  538. * @v xcm Configuration manager
  539. * @v msg Session message
  540. * @ret rc Return status code
  541. */
  542. static int xsmp_rx_session ( struct xsigo_manager *xcm,
  543. struct xsmp_session_message *msg ) {
  544. DBGCP ( xcm, "XCM %s RX[%d] session %s\n", xcm->name,
  545. ntohl ( msg->hdr.seq ), xsmp_session_type ( msg->type ) );
  546. DBGCP_HDA ( xcm, 0, msg, sizeof ( *msg ) );
  547. /* Handle message according to type */
  548. switch ( msg->type ) {
  549. case XSMP_SESSION_TYPE_HELLO:
  550. return xsmp_rx_session_hello ( xcm, msg );
  551. case XSMP_SESSION_TYPE_CONFIRM:
  552. return xsmp_rx_session_confirm ( xcm, msg );
  553. case XSMP_SESSION_TYPE_REJECT:
  554. return xsmp_rx_session_reject ( xcm, msg );
  555. case XSMP_SESSION_TYPE_SHUTDOWN:
  556. return xsmp_rx_session_shutdown ( xcm, msg );
  557. default:
  558. DBGC ( xcm, "XCM %s RX[%d] session unexpected %s:\n", xcm->name,
  559. ntohl ( msg->hdr.seq ), xsmp_session_type ( msg->type ));
  560. DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) );
  561. return -EPROTO;
  562. }
  563. }
  564. /****************************************************************************
  565. *
  566. * Server management protocol (XSMP) virtual Ethernet (XVE) messages
  567. *
  568. ****************************************************************************
  569. */
  570. /**
  571. * Get virtual Ethernet message name (for debugging)
  572. *
  573. * @v type Message type
  574. * @ret name Message name
  575. */
  576. static const char * xsmp_xve_type ( unsigned int type ) {
  577. static char buf[16];
  578. switch ( type ) {
  579. case XSMP_XVE_TYPE_INSTALL: return "INSTALL";
  580. case XSMP_XVE_TYPE_DELETE: return "DELETE";
  581. case XSMP_XVE_TYPE_UPDATE: return "UPDATE";
  582. case XSMP_XVE_TYPE_OPER_UP: return "OPER_UP";
  583. case XSMP_XVE_TYPE_OPER_DOWN: return "OPER_DOWN";
  584. case XSMP_XVE_TYPE_OPER_REQ: return "OPER_REQ";
  585. case XSMP_XVE_TYPE_READY: return "READY";
  586. default:
  587. snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", type );
  588. return buf;
  589. }
  590. }
  591. /**
  592. * Send virtual Ethernet message
  593. *
  594. * @v xcm Configuration manager
  595. * @v msg Partial message
  596. * @ret rc Return status code
  597. */
  598. static int xsmp_tx_xve ( struct xsigo_manager *xcm,
  599. struct xsmp_xve_message *msg ) {
  600. struct xsigo_device *xdev = xcm->xdev;
  601. struct ib_device *ibdev = xdev->ibdev;
  602. int rc;
  603. /* Fill in common header fields */
  604. msg->hdr.type = XSMP_TYPE_XVE;
  605. msg->hdr.len = htons ( sizeof ( *msg ) );
  606. msg->hdr.seq = htonl ( ++xcm->seq );
  607. memcpy ( &msg->hdr.src.guid, &ibdev->gid.s.guid,
  608. sizeof ( msg->hdr.src.guid ) );
  609. memcpy ( &msg->hdr.dst.guid, &xcm->id.guid,
  610. sizeof ( msg->hdr.dst.guid ) );
  611. msg->len = htons ( sizeof ( *msg ) - sizeof ( msg->hdr ) );
  612. DBGCP ( xcm, "XCM %s TX[%d] xve %s code %#02x\n", xcm->name,
  613. ntohl ( msg->hdr.seq ), xsmp_xve_type ( msg->type ),
  614. msg->code );
  615. DBGCP_HDA ( xcm, 0, msg, sizeof ( *msg ) );
  616. /* Send virtual Ethernet message */
  617. if ( ( rc = xfer_deliver_raw ( &xcm->xfer, msg,
  618. sizeof ( *msg ) ) ) != 0 ) {
  619. DBGC ( xcm, "XCM %s TX xve %s failed: %s\n", xcm->name,
  620. xsmp_xve_type ( msg->type ), strerror ( rc ) );
  621. return rc;
  622. }
  623. return 0;
  624. }
  625. /**
  626. * Send virtual Ethernet message including current device parameters
  627. *
  628. * @v xcm Configuration manager
  629. * @v msg Partial virtual Ethernet message
  630. * @v xve Virtual Ethernet device
  631. * @v eoib EoIB device
  632. * @ret rc Return status code
  633. */
  634. static int xsmp_tx_xve_params ( struct xsigo_manager *xcm,
  635. struct xsmp_xve_message *msg,
  636. struct xsigo_nic *xve,
  637. struct eoib_device *eoib ) {
  638. struct xsigo_device *xdev = xcm->xdev;
  639. struct ib_device *ibdev = xdev->ibdev;
  640. struct net_device *netdev = eoib->netdev;
  641. /* Set successful response code */
  642. msg->code = 0;
  643. /* Include network identifier, MTU, and current HCA parameters */
  644. msg->network = htonl ( xve->network );
  645. msg->mtu = htons ( netdev->max_pkt_len - sizeof ( struct ethhdr ) );
  646. msg->hca.prefix_le.qword = bswap_64 ( ibdev->gid.s.prefix.qword );
  647. msg->hca.pkey = htons ( ibdev->pkey );
  648. msg->hca.qkey = msg->tca.qkey;
  649. if ( eoib->qp ) {
  650. msg->hca.data = htonl ( eoib->qp->ext_qpn );
  651. msg->hca.qkey = htons ( eoib->qp->qkey );
  652. }
  653. /* The message type field is (ab)used to return the current
  654. * operational status.
  655. */
  656. if ( msg->type == XSMP_XVE_TYPE_OPER_REQ ) {
  657. msg->type = ( netdev_is_open ( netdev ) ?
  658. XSMP_XVE_TYPE_OPER_UP : XSMP_XVE_TYPE_OPER_DOWN );
  659. }
  660. /* Send message */
  661. DBGC ( xve, "XVE %s network %d MTU %d ctrl %#x data %#x qkey %#04x "
  662. "%s\n", xve->name, ntohl ( msg->network ), ntohs ( msg->mtu ),
  663. ntohl ( msg->hca.ctrl ), ntohl ( msg->hca.data ),
  664. ntohs ( msg->hca.qkey ), xsmp_xve_type ( msg->type ) );
  665. return xsmp_tx_xve ( xcm, msg );
  666. }
  667. /**
  668. * Send virtual Ethernet error response
  669. *
  670. * @v xcm Configuration manager
  671. * @v msg Partial virtual Ethernet message
  672. * @ret rc Return status code
  673. */
  674. static inline int xsmp_tx_xve_nack ( struct xsigo_manager *xcm,
  675. struct xsmp_xve_message *msg ) {
  676. /* Set error response code. (There aren't any meaningful
  677. * detailed response codes defined by the wire protocol.)
  678. */
  679. msg->code = XSMP_XVE_CODE_ERROR;
  680. /* Send message */
  681. return xsmp_tx_xve ( xcm, msg );
  682. }
  683. /**
  684. * Send virtual Ethernet notification
  685. *
  686. * @v xcm Configuration manager
  687. * @v type Message type
  688. * @v xve Virtual Ethernet device
  689. * @v eoib EoIB device
  690. * @ret rc Return status code
  691. */
  692. static int xsmp_tx_xve_notify ( struct xsigo_manager *xcm,
  693. unsigned int type,
  694. struct xsigo_nic *xve,
  695. struct eoib_device *eoib ) {
  696. struct xsmp_xve_message msg;
  697. /* Construct message */
  698. memset ( &msg, 0, sizeof ( msg ) );
  699. msg.type = type;
  700. memcpy ( &msg.resource, &xve->resource, sizeof ( msg.resource ) );
  701. /* Send message */
  702. return xsmp_tx_xve_params ( xcm, &msg, xve, eoib );
  703. }
  704. /**
  705. * Send virtual Ethernet current operational state
  706. *
  707. * @v xcm Configuration manager
  708. * @v xve Virtual Ethernet device
  709. * @v eoib EoIB device
  710. * @ret rc Return status code
  711. */
  712. static inline int xsmp_tx_xve_oper ( struct xsigo_manager *xcm,
  713. struct xsigo_nic *xve,
  714. struct eoib_device *eoib ) {
  715. /* Send notification */
  716. return xsmp_tx_xve_notify ( xcm, XSMP_XVE_TYPE_OPER_REQ, xve, eoib );
  717. }
  718. /**
  719. * Handle received virtual Ethernet modification message
  720. *
  721. * @v xcm Configuration manager
  722. * @v msg Virtual Ethernet message
  723. * @v update Update bitmask
  724. * @ret rc Return status code
  725. */
  726. static int xsmp_rx_xve_modify ( struct xsigo_manager *xcm,
  727. struct xsmp_xve_message *msg,
  728. unsigned int update ) {
  729. struct xsigo_device *xdev = xcm->xdev;
  730. struct ib_device *ibdev = xdev->ibdev;
  731. struct xsigo_nic *xve;
  732. struct eoib_device *eoib;
  733. struct ib_address_vector tca;
  734. size_t mtu;
  735. int rc;
  736. /* Avoid returning uninitialised HCA parameters in response */
  737. memset ( &msg->hca, 0, sizeof ( msg->hca ) );
  738. /* Find virtual Ethernet device */
  739. xve = xve_find ( xcm, &msg->resource );
  740. if ( ! xve ) {
  741. DBGC ( xcm, "XCM %s unrecognised resource " IB_GUID_FMT "\n",
  742. xcm->name, IB_GUID_ARGS ( &msg->resource ) );
  743. rc = -ENOENT;
  744. goto err_no_xve;
  745. }
  746. /* Find corresponding EoIB device */
  747. eoib = eoib_find ( ibdev, xve->mac );
  748. if ( ! eoib ) {
  749. DBGC ( xve, "XVE %s has no EoIB device\n", xve->name );
  750. rc = -EPIPE;
  751. goto err_no_eoib;
  752. }
  753. /* The Xsigo management software fails to create the EoIB
  754. * multicast group. This is a fundamental design flaw.
  755. */
  756. eoib_force_group_creation ( eoib );
  757. /* Extract modifiable parameters. Note that the TCA GID is
  758. * erroneously transmitted as little-endian.
  759. */
  760. mtu = ntohs ( msg->mtu );
  761. tca.qpn = ntohl ( msg->tca.data );
  762. tca.qkey = ntohs ( msg->tca.qkey );
  763. tca.gid_present = 1;
  764. tca.gid.s.prefix.qword = bswap_64 ( msg->tca.prefix_le.qword );
  765. tca.gid.s.guid.qword = bswap_64 ( msg->guid_le.qword );
  766. /* Update MTU, if applicable */
  767. if ( ( update & XSMP_XVE_UPDATE_MTU ) &&
  768. ( ( rc = xve_update_mtu ( xve, eoib, mtu ) ) != 0 ) )
  769. goto err_mtu;
  770. update &= ~XSMP_XVE_UPDATE_MTU;
  771. /* Update admin state, if applicable */
  772. if ( ( update & XSMP_XVE_UPDATE_STATE ) &&
  773. ( ( rc = xve_update_state ( xve, eoib, msg->state ) ) != 0 ) )
  774. goto err_state;
  775. update &= ~XSMP_XVE_UPDATE_STATE;
  776. /* Remove gateway, if applicable */
  777. if ( ( update & XSMP_XVE_UPDATE_GW_DOWN ) &&
  778. ( ( rc = xve_update_tca ( xve, eoib, NULL ) ) != 0 ) )
  779. goto err_gw_down;
  780. update &= ~XSMP_XVE_UPDATE_GW_DOWN;
  781. /* Update gateway, if applicable */
  782. if ( ( update & XSMP_XVE_UPDATE_GW_CHANGE ) &&
  783. ( ( rc = xve_update_tca ( xve, eoib, &tca ) ) != 0 ) )
  784. goto err_gw_change;
  785. update &= ~XSMP_XVE_UPDATE_GW_CHANGE;
  786. /* Warn about unexpected updates */
  787. if ( update ) {
  788. DBGC ( xve, "XVE %s unrecognised update(s) %#08x\n",
  789. xve->name, update );
  790. }
  791. xsmp_tx_xve_params ( xcm, msg, xve, eoib );
  792. return 0;
  793. err_gw_change:
  794. err_gw_down:
  795. err_state:
  796. err_mtu:
  797. err_no_eoib:
  798. err_no_xve:
  799. /* Send NACK */
  800. xsmp_tx_xve_nack ( xcm, msg );
  801. return rc;
  802. }
  803. /**
  804. * Handle received virtual Ethernet installation message
  805. *
  806. * @v xcm Configuration manager
  807. * @v msg Virtual Ethernet message
  808. * @ret rc Return status code
  809. */
  810. static int xsmp_rx_xve_install ( struct xsigo_manager *xcm,
  811. struct xsmp_xve_message *msg ) {
  812. union {
  813. struct xsmp_xve_mac msg;
  814. uint8_t raw[ETH_ALEN];
  815. } mac;
  816. char name[ sizeof ( msg->name ) + 1 /* NUL */ ];
  817. unsigned long network;
  818. unsigned long qkey;
  819. unsigned int update;
  820. int rc;
  821. /* Demangle MAC address (which is erroneously transmitted as
  822. * little-endian).
  823. */
  824. mac.msg.high = bswap_16 ( msg->mac_le.high );
  825. mac.msg.low = bswap_32 ( msg->mac_le.low );
  826. /* Extract interface name (which may not be NUL-terminated) */
  827. memcpy ( name, msg->name, ( sizeof ( name ) - 1 /* NUL */ ) );
  828. name[ sizeof ( name ) - 1 /* NUL */ ] = '\0';
  829. /* Extract remaining message parameters */
  830. network = ntohl ( msg->network );
  831. qkey = ntohs ( msg->tca.qkey );
  832. DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " install \"%s\" %s net %ld qkey "
  833. "%#lx\n", xcm->name, IB_GUID_ARGS ( &msg->resource ), name,
  834. eth_ntoa ( mac.raw ), network, qkey );
  835. /* Create virtual Ethernet device, if applicable */
  836. if ( ( xve_find ( xcm, &msg->resource ) == NULL ) &&
  837. ( ( rc = xve_create ( xcm, &msg->resource, mac.raw, network,
  838. qkey, name ) ) != 0 ) )
  839. goto err_create;
  840. /* Handle remaining parameters as for a modification message */
  841. update = XSMP_XVE_UPDATE_MTU;
  842. if ( msg->uplink == XSMP_XVE_UPLINK )
  843. update |= XSMP_XVE_UPDATE_GW_CHANGE;
  844. return xsmp_rx_xve_modify ( xcm, msg, update );
  845. err_create:
  846. /* Send NACK */
  847. xsmp_tx_xve_nack ( xcm, msg );
  848. return rc;
  849. }
  850. /**
  851. * Handle received virtual Ethernet deletion message
  852. *
  853. * @v xcm Configuration manager
  854. * @v msg Virtual Ethernet message
  855. * @ret rc Return status code
  856. */
  857. static int xsmp_rx_xve_delete ( struct xsigo_manager *xcm,
  858. struct xsmp_xve_message *msg ) {
  859. struct xsigo_nic *xve;
  860. DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " delete\n",
  861. xcm->name, IB_GUID_ARGS ( &msg->resource ) );
  862. /* Destroy virtual Ethernet device (if any) */
  863. if ( ( xve = xve_find ( xcm, &msg->resource ) ) )
  864. xve_destroy ( xve );
  865. /* Send ACK */
  866. msg->code = 0;
  867. xsmp_tx_xve ( xcm, msg );
  868. return 0;
  869. }
  870. /**
  871. * Handle received virtual Ethernet update message
  872. *
  873. * @v xcm Configuration manager
  874. * @v msg Virtual Ethernet message
  875. * @ret rc Return status code
  876. */
  877. static int xsmp_rx_xve_update ( struct xsigo_manager *xcm,
  878. struct xsmp_xve_message *msg ) {
  879. unsigned int update = ntohl ( msg->update );
  880. DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " update (%08x)\n",
  881. xcm->name, IB_GUID_ARGS ( &msg->resource ), update );
  882. /* Handle as a modification message */
  883. return xsmp_rx_xve_modify ( xcm, msg, update );
  884. }
  885. /**
  886. * Handle received virtual Ethernet operational request message
  887. *
  888. * @v xcm Configuration manager
  889. * @v msg Virtual Ethernet message
  890. * @ret rc Return status code
  891. */
  892. static int xsmp_rx_xve_oper_req ( struct xsigo_manager *xcm,
  893. struct xsmp_xve_message *msg ) {
  894. DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " operational request\n",
  895. xcm->name, IB_GUID_ARGS ( &msg->resource ) );
  896. /* Handle as a nullipotent modification message */
  897. return xsmp_rx_xve_modify ( xcm, msg, 0 );
  898. }
  899. /**
  900. * Handle received virtual Ethernet readiness message
  901. *
  902. * @v xcm Configuration manager
  903. * @v msg Virtual Ethernet message
  904. * @ret rc Return status code
  905. */
  906. static int xsmp_rx_xve_ready ( struct xsigo_manager *xcm,
  907. struct xsmp_xve_message *msg ) {
  908. int rc;
  909. DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " ready\n",
  910. xcm->name, IB_GUID_ARGS ( &msg->resource ) );
  911. /* Handle as a nullipotent modification message */
  912. if ( ( rc = xsmp_rx_xve_modify ( xcm, msg, 0 ) ) != 0 )
  913. return rc;
  914. /* Send an unsolicited operational state update, since there
  915. * is no other way to convey the current operational state.
  916. */
  917. msg->type = XSMP_XVE_TYPE_OPER_REQ;
  918. if ( ( rc = xsmp_rx_xve_modify ( xcm, msg, 0 ) ) != 0 )
  919. return rc;
  920. return 0;
  921. }
  922. /**
  923. * Handle received virtual Ethernet message
  924. *
  925. * @v xcm Configuration manager
  926. * @v msg Virtual Ethernet message
  927. * @ret rc Return status code
  928. */
  929. static int xsmp_rx_xve ( struct xsigo_manager *xcm,
  930. struct xsmp_xve_message *msg ) {
  931. DBGCP ( xcm, "XCM %s RX[%d] xve %s\n", xcm->name,
  932. ntohl ( msg->hdr.seq ), xsmp_xve_type ( msg->type ) );
  933. DBGCP_HDA ( xcm, 0, msg, sizeof ( *msg ) );
  934. /* Handle message according to type */
  935. switch ( msg->type ) {
  936. case XSMP_XVE_TYPE_INSTALL:
  937. return xsmp_rx_xve_install ( xcm, msg );
  938. case XSMP_XVE_TYPE_DELETE:
  939. return xsmp_rx_xve_delete ( xcm, msg );
  940. case XSMP_XVE_TYPE_UPDATE:
  941. return xsmp_rx_xve_update ( xcm, msg );
  942. case XSMP_XVE_TYPE_OPER_REQ:
  943. return xsmp_rx_xve_oper_req ( xcm, msg );
  944. case XSMP_XVE_TYPE_READY:
  945. return xsmp_rx_xve_ready ( xcm, msg );
  946. default:
  947. DBGC ( xcm, "XCM %s RX[%d] xve unexpected %s:\n", xcm->name,
  948. ntohl ( msg->hdr.seq ), xsmp_xve_type ( msg->type ) );
  949. DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) );
  950. return -EPROTO;
  951. }
  952. }
  953. /****************************************************************************
  954. *
  955. * Configuration managers (XCM)
  956. *
  957. ****************************************************************************
  958. */
  959. /**
  960. * Close configuration manager connection
  961. *
  962. * @v xcm Configuration manager
  963. * @v rc Reason for close
  964. */
  965. static void xcm_close ( struct xsigo_manager *xcm, int rc ) {
  966. DBGC ( xcm, "XCM %s closed: %s\n", xcm->name, strerror ( rc ) );
  967. /* Stop transmission process */
  968. process_del ( &xcm->process );
  969. /* Stop keepalive timer */
  970. stop_timer ( &xcm->keepalive );
  971. /* Restart data transfer interface */
  972. intf_restart ( &xcm->xfer, rc );
  973. /* Schedule reconnection attempt */
  974. start_timer ( &xcm->reopen );
  975. }
  976. /**
  977. * Send data to configuration manager
  978. *
  979. * @v xcm Configuration manager
  980. */
  981. static void xcm_step ( struct xsigo_manager *xcm ) {
  982. int rc;
  983. /* Do nothing unless we have something to send */
  984. if ( ! xcm->pending )
  985. return;
  986. /* Send (empty) connection request, if applicable */
  987. if ( xcm->pending & XCM_TX_CONNECT ) {
  988. if ( ( rc = xfer_deliver_raw ( &xcm->xfer, NULL, 0 ) ) != 0 ) {
  989. DBGC ( xcm, "XCM %s could not send connection request: "
  990. "%s\n", xcm->name, strerror ( rc ) );
  991. goto err;
  992. }
  993. xcm->pending &= ~XCM_TX_CONNECT;
  994. return;
  995. }
  996. /* Wait until data transfer interface is connected */
  997. if ( ! xfer_window ( &xcm->xfer ) )
  998. return;
  999. /* Send registration message, if applicable */
  1000. if ( xcm->pending & XCM_TX_REGISTER ) {
  1001. if ( ( rc = xsmp_tx_session_register ( xcm ) ) != 0 )
  1002. goto err;
  1003. xcm->pending &= ~XCM_TX_REGISTER;
  1004. return;
  1005. }
  1006. return;
  1007. err:
  1008. xcm_close ( xcm, rc );
  1009. }
  1010. /**
  1011. * Receive data from configuration manager
  1012. *
  1013. * @v xcm Configuration manager
  1014. * @v iobuf I/O buffer
  1015. * @v meta Data transfer metadata
  1016. * @ret rc Return status code
  1017. */
  1018. static int xcm_deliver ( struct xsigo_manager *xcm, struct io_buffer *iobuf,
  1019. struct xfer_metadata *meta __unused ) {
  1020. union xsmp_message *msg;
  1021. size_t len = iob_len ( iobuf );
  1022. int rc;
  1023. /* Sanity check */
  1024. if ( len < sizeof ( msg->hdr ) ) {
  1025. DBGC ( xcm, "XCM %s underlength message:\n", xcm->name );
  1026. DBGC_HDA ( xcm, 0, iobuf->data, iob_len ( iobuf ) );
  1027. rc = -EPROTO;
  1028. goto out;
  1029. }
  1030. msg = iobuf->data;
  1031. /* Handle message according to type */
  1032. if ( ! msg->hdr.type ) {
  1033. /* Ignore unused communication manager private data blocks */
  1034. rc = 0;
  1035. } else if ( ( msg->hdr.type == XSMP_TYPE_SESSION ) &&
  1036. ( len >= sizeof ( msg->sess ) ) ) {
  1037. /* Session message */
  1038. rc = xsmp_rx_session ( xcm, &msg->sess );
  1039. } else if ( ( msg->hdr.type == XSMP_TYPE_XVE ) &&
  1040. ( len >= sizeof ( msg->xve ) ) ) {
  1041. /* Virtual Ethernet message */
  1042. xsmp_rx_xve ( xcm, &msg->xve );
  1043. /* Virtual Ethernet message errors are non-fatal */
  1044. rc = 0;
  1045. } else {
  1046. /* Unknown message */
  1047. DBGC ( xcm, "XCM %s unexpected message type %d:\n",
  1048. xcm->name, msg->hdr.type );
  1049. DBGC_HDA ( xcm, 0, iobuf->data, iob_len ( iobuf ) );
  1050. rc = -EPROTO;
  1051. }
  1052. out:
  1053. free_iob ( iobuf );
  1054. if ( rc != 0 )
  1055. xcm_close ( xcm, rc );
  1056. return rc;
  1057. }
  1058. /** Configuration manager data transfer interface operations */
  1059. static struct interface_operation xcm_xfer_op[] = {
  1060. INTF_OP ( xfer_deliver, struct xsigo_manager *, xcm_deliver ),
  1061. INTF_OP ( xfer_window_changed, struct xsigo_manager *, xcm_step ),
  1062. INTF_OP ( intf_close, struct xsigo_manager *, xcm_close ),
  1063. };
  1064. /** Configuration manager data transfer interface descriptor */
  1065. static struct interface_descriptor xcm_xfer_desc =
  1066. INTF_DESC ( struct xsigo_manager, xfer, xcm_xfer_op );
  1067. /** Configuration manager process descriptor */
  1068. static struct process_descriptor xcm_process_desc =
  1069. PROC_DESC_ONCE ( struct xsigo_manager, process, xcm_step );
  1070. /**
  1071. * Handle configuration manager connection timer expiry
  1072. *
  1073. * @v timer Connection timer
  1074. * @v fail Failure indicator
  1075. */
  1076. static void xcm_reopen ( struct retry_timer *timer, int fail __unused ) {
  1077. struct xsigo_manager *xcm =
  1078. container_of ( timer, struct xsigo_manager, reopen );
  1079. struct xsigo_device *xdev = xcm->xdev;
  1080. struct ib_device *ibdev = xdev->ibdev;
  1081. union ib_gid gid;
  1082. int rc;
  1083. /* Stop transmission process */
  1084. process_del ( &xcm->process );
  1085. /* Stop keepalive timer */
  1086. stop_timer ( &xcm->keepalive );
  1087. /* Restart data transfer interface */
  1088. intf_restart ( &xcm->xfer, -ECANCELED );
  1089. /* Reset sequence number */
  1090. xcm->seq = 0;
  1091. /* Construct GID */
  1092. memcpy ( &gid.s.prefix, &ibdev->gid.s.prefix, sizeof ( gid.s.prefix ) );
  1093. memcpy ( &gid.s.guid, &xcm->id.guid, sizeof ( gid.s.guid ) );
  1094. DBGC ( xcm, "XCM %s connecting to " IB_GID_FMT "\n",
  1095. xcm->name, IB_GID_ARGS ( &gid ) );
  1096. /* Open CMRC connection */
  1097. if ( ( rc = ib_cmrc_open ( &xcm->xfer, ibdev, &gid,
  1098. &xcm_service_id, xcm->name ) ) != 0 ) {
  1099. DBGC ( xcm, "XCM %s could not open CMRC connection: %s\n",
  1100. xcm->name, strerror ( rc ) );
  1101. start_timer ( &xcm->reopen );
  1102. return;
  1103. }
  1104. /* Schedule transmissions */
  1105. xcm->pending |= ( XCM_TX_CONNECT | XCM_TX_REGISTER );
  1106. process_add ( &xcm->process );
  1107. /* Start keepalive timer */
  1108. start_timer_fixed ( &xcm->keepalive, XSIGO_KEEPALIVE_INTERVAL );
  1109. return;
  1110. }
  1111. /**
  1112. * Handle configuration manager keepalive timer expiry
  1113. *
  1114. * @v timer Connection timer
  1115. * @v fail Failure indicator
  1116. */
  1117. static void xcm_keepalive ( struct retry_timer *timer, int fail __unused ) {
  1118. struct xsigo_manager *xcm =
  1119. container_of ( timer, struct xsigo_manager, keepalive );
  1120. int rc;
  1121. /* Send keepalive message. The server won't actually respond
  1122. * to these, but it gives the RC queue pair a chance to
  1123. * complain if it doesn't ever at least get an ACK.
  1124. */
  1125. if ( ( rc = xsmp_tx_session_hello ( xcm ) ) != 0 ) {
  1126. xcm_close ( xcm, rc );
  1127. return;
  1128. }
  1129. /* Restart keepalive timer */
  1130. start_timer_fixed ( &xcm->keepalive, XSIGO_KEEPALIVE_INTERVAL );
  1131. }
  1132. /**
  1133. * Create configuration manager
  1134. *
  1135. * @v xsigo Xsigo device
  1136. * @v id Configuration manager ID
  1137. * @ret rc Return status code
  1138. */
  1139. static int xcm_create ( struct xsigo_device *xdev,
  1140. struct xsigo_manager_id *id ) {
  1141. struct xsigo_manager *xcm;
  1142. /* Allocate and initialise structure */
  1143. xcm = zalloc ( sizeof ( *xcm ) );
  1144. if ( ! xcm )
  1145. return -ENOMEM;
  1146. ref_init ( &xcm->refcnt, xcm_free );
  1147. xcm->xdev = xdev;
  1148. ref_get ( &xcm->xdev->refcnt );
  1149. snprintf ( xcm->name, sizeof ( xcm->name ), "%s:xcm-%d",
  1150. xdev->name, ntohs ( id->lid ) );
  1151. memcpy ( &xcm->id, id, sizeof ( xcm->id ) );
  1152. intf_init ( &xcm->xfer, &xcm_xfer_desc, &xcm->refcnt );
  1153. timer_init ( &xcm->keepalive, xcm_keepalive, &xcm->refcnt );
  1154. timer_init ( &xcm->reopen, xcm_reopen, &xcm->refcnt );
  1155. process_init_stopped ( &xcm->process, &xcm_process_desc, &xcm->refcnt );
  1156. INIT_LIST_HEAD ( &xcm->nics );
  1157. /* Start timer to open connection */
  1158. start_timer_nodelay ( &xcm->reopen );
  1159. /* Add to list of managers and transfer reference to list */
  1160. list_add ( &xcm->list, &xdev->managers );
  1161. DBGC ( xcm, "XCM %s created for " IB_GUID_FMT " (LID %d)\n", xcm->name,
  1162. IB_GUID_ARGS ( &xcm->id.guid ), ntohs ( id->lid ) );
  1163. return 0;
  1164. }
  1165. /**
  1166. * Find configuration manager
  1167. *
  1168. * @v xsigo Xsigo device
  1169. * @v id Configuration manager ID
  1170. * @ret xcm Configuration manager, or NULL
  1171. */
  1172. static struct xsigo_manager * xcm_find ( struct xsigo_device *xdev,
  1173. struct xsigo_manager_id *id ) {
  1174. struct xsigo_manager *xcm;
  1175. union ib_guid *guid = &id->guid;
  1176. /* Find configuration manager */
  1177. list_for_each_entry ( xcm, &xdev->managers, list ) {
  1178. if ( memcmp ( guid, &xcm->id.guid, sizeof ( *guid ) ) == 0 )
  1179. return xcm;
  1180. }
  1181. return NULL;
  1182. }
  1183. /**
  1184. * Destroy configuration manager
  1185. *
  1186. * @v xcm Configuration manager
  1187. */
  1188. static void xcm_destroy ( struct xsigo_manager *xcm ) {
  1189. struct xsigo_nic *xve;
  1190. /* Remove all EoIB NICs */
  1191. while ( ( xve = list_first_entry ( &xcm->nics, struct xsigo_nic,
  1192. list ) ) ) {
  1193. xve_destroy ( xve );
  1194. }
  1195. /* Stop transmission process */
  1196. process_del ( &xcm->process );
  1197. /* Stop timers */
  1198. stop_timer ( &xcm->keepalive );
  1199. stop_timer ( &xcm->reopen );
  1200. /* Shut down data transfer interface */
  1201. intf_shutdown ( &xcm->xfer, 0 );
  1202. /* Remove from list of managers and drop list's reference */
  1203. DBGC ( xcm, "XCM %s destroyed\n", xcm->name );
  1204. list_del ( &xcm->list );
  1205. ref_put ( &xcm->refcnt );
  1206. }
  1207. /**
  1208. * Synchronise list of configuration managers
  1209. *
  1210. * @v xdev Xsigo device
  1211. * @v ids List of manager IDs
  1212. * @v count Number of manager IDs
  1213. * @ret rc Return status code
  1214. */
  1215. static int xcm_list ( struct xsigo_device *xdev, struct xsigo_manager_id *ids,
  1216. unsigned int count ) {
  1217. struct xsigo_manager_id *id;
  1218. struct xsigo_manager *xcm;
  1219. struct xsigo_manager *tmp;
  1220. struct list_head list;
  1221. unsigned int i;
  1222. int rc;
  1223. /* Create list of managers to be retained */
  1224. INIT_LIST_HEAD ( &list );
  1225. for ( i = 0, id = ids ; i < count ; i++, id++ ) {
  1226. if ( ( xcm = xcm_find ( xdev, id ) ) ) {
  1227. list_del ( &xcm->list );
  1228. list_add_tail ( &xcm->list, &list );
  1229. }
  1230. }
  1231. /* Destroy any managers not in the list */
  1232. list_for_each_entry_safe ( xcm, tmp, &xdev->managers, list )
  1233. xcm_destroy ( xcm );
  1234. list_splice ( &list, &xdev->managers );
  1235. /* Create any new managers in the list, and force reconnection
  1236. * for any changed LIDs.
  1237. */
  1238. for ( i = 0, id = ids ; i < count ; i++, id++ ) {
  1239. if ( ( xcm = xcm_find ( xdev, id ) ) ) {
  1240. if ( xcm->id.lid != id->lid )
  1241. start_timer_nodelay ( &xcm->reopen );
  1242. continue;
  1243. }
  1244. if ( ( rc = xcm_create ( xdev, id ) ) != 0 ) {
  1245. DBGC ( xdev, "XDEV %s could not create manager: %s\n",
  1246. xdev->name, strerror ( rc ) );
  1247. return rc;
  1248. }
  1249. }
  1250. return 0;
  1251. }
  1252. /****************************************************************************
  1253. *
  1254. * Configuration manager discovery
  1255. *
  1256. ****************************************************************************
  1257. */
  1258. /** A stage of discovery */
  1259. struct xsigo_discovery {
  1260. /** Name */
  1261. const char *name;
  1262. /** Management transaction operations */
  1263. struct ib_mad_transaction_operations op;
  1264. };
  1265. /**
  1266. * Handle configuration manager lookup completion
  1267. *
  1268. * @v ibdev Infiniband device
  1269. * @v mi Management interface
  1270. * @v madx Management transaction
  1271. * @v rc Status code
  1272. * @v mad Received MAD (or NULL on error)
  1273. * @v av Source address vector (or NULL on error)
  1274. */
  1275. static void xsigo_xcm_complete ( struct ib_device *ibdev,
  1276. struct ib_mad_interface *mi __unused,
  1277. struct ib_mad_transaction *madx,
  1278. int rc, union ib_mad *mad,
  1279. struct ib_address_vector *av __unused ) {
  1280. struct xsigo_device *xdev = ib_madx_get_ownerdata ( madx );
  1281. union xsigo_mad *xsmad = container_of ( mad, union xsigo_mad, mad );
  1282. struct xsigo_managers_reply *reply = &xsmad->reply;
  1283. /* Check for failures */
  1284. if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) ) )
  1285. rc = -ENODEV;
  1286. if ( rc != 0 ) {
  1287. DBGC ( xdev, "XDEV %s manager lookup failed: %s\n",
  1288. xdev->name, strerror ( rc ) );
  1289. goto out;
  1290. }
  1291. /* Sanity checks */
  1292. if ( reply->count > ( sizeof ( reply->manager ) /
  1293. sizeof ( reply->manager[0] ) ) ) {
  1294. DBGC ( xdev, "XDEV %s has too many managers (%d)\n",
  1295. xdev->name, reply->count );
  1296. goto out;
  1297. }
  1298. /* Synchronise list of managers */
  1299. if ( ( rc = xcm_list ( xdev, reply->manager, reply->count ) ) != 0 )
  1300. goto out;
  1301. /* Report an empty list of managers */
  1302. if ( reply->count == 0 )
  1303. DBGC ( xdev, "XDEV %s has no managers\n", xdev->name );
  1304. /* Delay next discovery attempt */
  1305. start_timer_fixed ( &xdev->discovery, XSIGO_DISCOVERY_SUCCESS_DELAY );
  1306. out:
  1307. /* Destroy the completed transaction */
  1308. ib_destroy_madx ( ibdev, ibdev->gsi, madx );
  1309. xdev->madx = NULL;
  1310. }
  1311. /** Configuration manager lookup discovery stage */
  1312. static struct xsigo_discovery xsigo_xcm_discovery = {
  1313. .name = "manager",
  1314. .op = {
  1315. .complete = xsigo_xcm_complete,
  1316. },
  1317. };
  1318. /**
  1319. * Handle directory service lookup completion
  1320. *
  1321. * @v ibdev Infiniband device
  1322. * @v mi Management interface
  1323. * @v madx Management transaction
  1324. * @v rc Status code
  1325. * @v mad Received MAD (or NULL on error)
  1326. * @v av Source address vector (or NULL on error)
  1327. */
  1328. static void xsigo_xds_complete ( struct ib_device *ibdev,
  1329. struct ib_mad_interface *mi __unused,
  1330. struct ib_mad_transaction *madx,
  1331. int rc, union ib_mad *mad,
  1332. struct ib_address_vector *av __unused ) {
  1333. struct xsigo_device *xdev = ib_madx_get_ownerdata ( madx );
  1334. union xsigo_mad *xsmad = container_of ( mad, union xsigo_mad, mad );
  1335. struct xsigo_managers_request *request = &xsmad->request;
  1336. struct ib_service_record *svc;
  1337. struct ib_address_vector dest;
  1338. union ib_guid *guid;
  1339. /* Allow for reuse of transaction pointer */
  1340. xdev->madx = NULL;
  1341. /* Check for failures */
  1342. if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) ) )
  1343. rc = -ENODEV;
  1344. if ( rc != 0 ) {
  1345. DBGC ( xdev, "XDEV %s directory lookup failed: %s\n",
  1346. xdev->name, strerror ( rc ) );
  1347. goto out;
  1348. }
  1349. /* Construct address vector */
  1350. memset ( &dest, 0, sizeof ( dest ) );
  1351. svc = &mad->sa.sa_data.service_record;
  1352. dest.lid = ntohs ( svc->data16[0] );
  1353. dest.sl = ibdev->sm_sl;
  1354. dest.qpn = IB_QPN_GSI;
  1355. dest.qkey = IB_QKEY_GSI;
  1356. guid = ( ( union ib_guid * ) &svc->data64[0] );
  1357. DBGC2 ( xdev, "XDEV %s found directory at LID %d GUID " IB_GUID_FMT
  1358. "\n", xdev->name, dest.lid, IB_GUID_ARGS ( guid ) );
  1359. /* Construct request (reusing MAD buffer) */
  1360. memset ( request, 0, sizeof ( *request ) );
  1361. request->mad_hdr.mgmt_class = XSIGO_MGMT_CLASS;
  1362. request->mad_hdr.class_version = XSIGO_MGMT_CLASS_VERSION;
  1363. request->mad_hdr.method = IB_MGMT_METHOD_GET;
  1364. request->mad_hdr.attr_id = htons ( XSIGO_ATTR_XCM_REQUEST );
  1365. memcpy ( &request->server.guid, &ibdev->gid.s.guid,
  1366. sizeof ( request->server.guid ) );
  1367. snprintf ( request->os_version, sizeof ( request->os_version ),
  1368. "%s %s", product_short_name, product_version );
  1369. snprintf ( request->arch, sizeof ( request->arch ), _S2 ( ARCH ) );
  1370. request->os_type = XSIGO_OS_TYPE_GENERIC;
  1371. request->resources = htons ( XSIGO_RESOURCES_PRESENT |
  1372. XSIGO_RESOURCE_XVE |
  1373. XSIGO_RESOURCE_NO_HA );
  1374. /* The handling of this request on the server side is a
  1375. * textbook example of how not to design a wire protocol. The
  1376. * server uses the _driver_ version number to determine which
  1377. * fields are present.
  1378. */
  1379. request->driver_version = htonl ( 0x2a2a2a );
  1380. /* The build version field is ignored unless it happens to
  1381. * contain the substring "xg-".
  1382. */
  1383. snprintf ( request->build, sizeof ( request->build ),
  1384. "not-xg-%08lx", build_id );
  1385. /* The server side user interface occasionally has no way to
  1386. * refer to an entry with an empty hostname.
  1387. */
  1388. fetch_string_setting ( NULL, &hostname_setting, request->hostname,
  1389. sizeof ( request->hostname ) );
  1390. if ( ! request->hostname[0] ) {
  1391. snprintf ( request->hostname, sizeof ( request->hostname ),
  1392. "%s-" IB_GUID_FMT, product_short_name,
  1393. IB_GUID_ARGS ( &ibdev->gid.s.guid ) );
  1394. }
  1395. /* Start configuration manager lookup */
  1396. xdev->madx = ib_create_madx ( ibdev, ibdev->gsi, mad, &dest,
  1397. &xsigo_xcm_discovery.op );
  1398. if ( ! xdev->madx ) {
  1399. DBGC ( xdev, "XDEV %s could not start manager lookup\n",
  1400. xdev->name );
  1401. goto out;
  1402. }
  1403. ib_madx_set_ownerdata ( xdev->madx, xdev );
  1404. out:
  1405. /* Destroy the completed transaction */
  1406. ib_destroy_madx ( ibdev, ibdev->gsi, madx );
  1407. }
  1408. /** Directory service lookup discovery stage */
  1409. static struct xsigo_discovery xsigo_xds_discovery = {
  1410. .name = "directory",
  1411. .op = {
  1412. .complete = xsigo_xds_complete,
  1413. },
  1414. };
  1415. /**
  1416. * Discover configuration managers
  1417. *
  1418. * @v timer Retry timer
  1419. * @v over Failure indicator
  1420. */
  1421. static void xsigo_discover ( struct retry_timer *timer, int over __unused ) {
  1422. struct xsigo_device *xdev =
  1423. container_of ( timer, struct xsigo_device, discovery );
  1424. struct ib_device *ibdev = xdev->ibdev;
  1425. struct xsigo_discovery *discovery;
  1426. /* Restart timer */
  1427. start_timer_fixed ( &xdev->discovery, XSIGO_DISCOVERY_FAILURE_DELAY );
  1428. /* Cancel any pending discovery transaction */
  1429. if ( xdev->madx ) {
  1430. discovery = container_of ( xdev->madx->op,
  1431. struct xsigo_discovery, op );
  1432. DBGC ( xdev, "XDEV %s timed out waiting for %s lookup\n",
  1433. xdev->name, discovery->name );
  1434. ib_destroy_madx ( ibdev, ibdev->gsi, xdev->madx );
  1435. xdev->madx = NULL;
  1436. }
  1437. /* Start directory service lookup */
  1438. xdev->madx = ib_create_service_madx ( ibdev, ibdev->gsi,
  1439. XDS_SERVICE_NAME,
  1440. &xsigo_xds_discovery.op );
  1441. if ( ! xdev->madx ) {
  1442. DBGC ( xdev, "XDEV %s could not start directory lookup\n",
  1443. xdev->name );
  1444. return;
  1445. }
  1446. ib_madx_set_ownerdata ( xdev->madx, xdev );
  1447. }
  1448. /****************************************************************************
  1449. *
  1450. * Infiniband device driver
  1451. *
  1452. ****************************************************************************
  1453. */
  1454. /**
  1455. * Open link and start discovery
  1456. *
  1457. * @v opener Link opener
  1458. * @v over Failure indicator
  1459. */
  1460. static void xsigo_ib_open ( struct retry_timer *opener, int over __unused ) {
  1461. struct xsigo_device *xdev =
  1462. container_of ( opener, struct xsigo_device, opener );
  1463. struct ib_device *ibdev = xdev->ibdev;
  1464. int rc;
  1465. /* Open Infiniband device */
  1466. if ( ( rc = ib_open ( ibdev ) ) != 0 ) {
  1467. DBGC ( xdev, "XDEV %s could not open: %s\n",
  1468. xdev->name, strerror ( rc ) );
  1469. /* Delay and try again */
  1470. start_timer_fixed ( &xdev->opener, XSIGO_OPEN_RETRY_DELAY );
  1471. return;
  1472. }
  1473. /* If link is already up, then start discovery */
  1474. if ( ib_link_ok ( ibdev ) )
  1475. start_timer_nodelay ( &xdev->discovery );
  1476. }
  1477. /**
  1478. * Probe Xsigo device
  1479. *
  1480. * @v ibdev Infiniband device
  1481. * @ret rc Return status code
  1482. */
  1483. static int xsigo_ib_probe ( struct ib_device *ibdev ) {
  1484. struct xsigo_device *xdev;
  1485. /* Allocate and initialise structure */
  1486. xdev = zalloc ( sizeof ( *xdev ) );
  1487. if ( ! xdev )
  1488. return -ENOMEM;
  1489. ref_init ( &xdev->refcnt, xsigo_free );
  1490. xdev->ibdev = ibdev_get ( ibdev );
  1491. xdev->name = ibdev->name;
  1492. timer_init ( &xdev->opener, xsigo_ib_open, &xdev->refcnt );
  1493. timer_init ( &xdev->discovery, xsigo_discover, &xdev->refcnt );
  1494. INIT_LIST_HEAD ( &xdev->managers );
  1495. /* Start timer to open Infiniband device. (We are currently
  1496. * within the Infiniband device probe callback list; opening
  1497. * the device here would have interesting side-effects.)
  1498. */
  1499. start_timer_nodelay ( &xdev->opener );
  1500. /* Add to list of devices and transfer reference to list */
  1501. list_add_tail ( &xdev->list, &xsigo_devices );
  1502. DBGC ( xdev, "XDEV %s created for " IB_GUID_FMT "\n",
  1503. xdev->name, IB_GUID_ARGS ( &ibdev->gid.s.guid ) );
  1504. return 0;
  1505. }
  1506. /**
  1507. * Handle device or link status change
  1508. *
  1509. * @v ibdev Infiniband device
  1510. */
  1511. static void xsigo_ib_notify ( struct ib_device *ibdev ) {
  1512. struct xsigo_device *xdev;
  1513. /* Stop/restart discovery on any attached devices */
  1514. list_for_each_entry ( xdev, &xsigo_devices, list ) {
  1515. /* Skip non-attached devices */
  1516. if ( xdev->ibdev != ibdev )
  1517. continue;
  1518. /* Stop any ongoing discovery */
  1519. if ( xdev->madx ) {
  1520. ib_destroy_madx ( ibdev, ibdev->gsi, xdev->madx );
  1521. xdev->madx = NULL;
  1522. }
  1523. stop_timer ( &xdev->discovery );
  1524. /* If link is up, then start discovery */
  1525. if ( ib_link_ok ( ibdev ) )
  1526. start_timer_nodelay ( &xdev->discovery );
  1527. }
  1528. }
  1529. /**
  1530. * Remove Xsigo device
  1531. *
  1532. * @v ibdev Infiniband device
  1533. */
  1534. static void xsigo_ib_remove ( struct ib_device *ibdev ) {
  1535. struct xsigo_device *xdev;
  1536. struct xsigo_device *tmp;
  1537. /* Remove any attached Xsigo devices */
  1538. list_for_each_entry_safe ( xdev, tmp, &xsigo_devices, list ) {
  1539. /* Skip non-attached devices */
  1540. if ( xdev->ibdev != ibdev )
  1541. continue;
  1542. /* Stop any ongoing discovery */
  1543. if ( xdev->madx ) {
  1544. ib_destroy_madx ( ibdev, ibdev->gsi, xdev->madx );
  1545. xdev->madx = NULL;
  1546. }
  1547. stop_timer ( &xdev->discovery );
  1548. /* Destroy all configuration managers */
  1549. xcm_list ( xdev, NULL, 0 );
  1550. /* Close Infiniband device, if applicable */
  1551. if ( ! timer_running ( &xdev->opener ) )
  1552. ib_close ( xdev->ibdev );
  1553. /* Stop link opener */
  1554. stop_timer ( &xdev->opener );
  1555. /* Remove from list of devices and drop list's reference */
  1556. DBGC ( xdev, "XDEV %s destroyed\n", xdev->name );
  1557. list_del ( &xdev->list );
  1558. ref_put ( &xdev->refcnt );
  1559. }
  1560. }
  1561. /** Xsigo Infiniband driver */
  1562. struct ib_driver xsigo_ib_driver __ib_driver = {
  1563. .name = "Xsigo",
  1564. .probe = xsigo_ib_probe,
  1565. .notify = xsigo_ib_notify,
  1566. .remove = xsigo_ib_remove,
  1567. };
  1568. /****************************************************************************
  1569. *
  1570. * Network device driver
  1571. *
  1572. ****************************************************************************
  1573. */
  1574. /**
  1575. * Handle device or link status change
  1576. *
  1577. * @v netdev Network device
  1578. */
  1579. static void xsigo_net_notify ( struct net_device *netdev ) {
  1580. struct xsigo_device *xdev;
  1581. struct ib_device *ibdev;
  1582. struct xsigo_manager *xcm;
  1583. struct xsigo_nic *xve;
  1584. struct eoib_device *eoib;
  1585. /* Send current operational state to XCM, if applicable */
  1586. list_for_each_entry ( xdev, &xsigo_devices, list ) {
  1587. ibdev = xdev->ibdev;
  1588. list_for_each_entry ( xcm, &xdev->managers, list ) {
  1589. list_for_each_entry ( xve, &xcm->nics, list ) {
  1590. eoib = eoib_find ( ibdev, xve->mac );
  1591. if ( ! eoib )
  1592. continue;
  1593. if ( eoib->netdev != netdev )
  1594. continue;
  1595. xsmp_tx_xve_oper ( xcm, xve, eoib );
  1596. }
  1597. }
  1598. }
  1599. }
  1600. /** Xsigo network driver */
  1601. struct net_driver xsigo_net_driver __net_driver = {
  1602. .name = "Xsigo",
  1603. .notify = xsigo_net_notify,
  1604. };