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.

flexboot_nodnic.c 47KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575
  1. /*
  2. * Copyright (C) 2015 Mellanox Technologies Ltd.
  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. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <stdio.h>
  21. #include <unistd.h>
  22. #include <errno.h>
  23. #include <ipxe/pci.h>
  24. #include <ipxe/malloc.h>
  25. #include <ipxe/umalloc.h>
  26. #include <ipxe/if_ether.h>
  27. #include <ipxe/ethernet.h>
  28. #include <ipxe/vlan.h>
  29. #include <ipxe/io.h>
  30. #include "flexboot_nodnic.h"
  31. #include "mlx_utils/include/public/mlx_types.h"
  32. #include "mlx_utils/include/public/mlx_utils.h"
  33. #include "mlx_utils/include/public/mlx_bail.h"
  34. #include "mlx_nodnic/include/mlx_cmd.h"
  35. #include "mlx_utils/include/public/mlx_memory.h"
  36. #include "mlx_utils/include/public/mlx_pci.h"
  37. #include "mlx_nodnic/include/mlx_device.h"
  38. #include "mlx_nodnic/include/mlx_port.h"
  39. #include <byteswap.h>
  40. #include <usr/ifmgmt.h>
  41. #include "mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig.h"
  42. #include "mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.h"
  43. #include "mlx_utils/include/public/mlx_pci_gw.h"
  44. #include "mlx_utils/mlx_lib/mlx_vmac/mlx_vmac.h"
  45. /***************************************************************************
  46. *
  47. * Completion queue operations
  48. *
  49. ***************************************************************************
  50. */
  51. static int flexboot_nodnic_arm_cq ( struct flexboot_nodnic_port *port ) {
  52. #ifndef DEVICE_CX3
  53. mlx_uint32 val32 = 0;
  54. union arm_cq_uar cq_uar;
  55. #define ARM_CQ_UAR_CQ_CI_MASK 0xffffff
  56. #define ARM_CQ_UAR_CMDSN_MASK 3
  57. #define ARM_CQ_UAR_CMDSN_OFFSET 28
  58. #define ARM_CQ_UAR_CQ_CI_OFFSET 0x20
  59. if ( port->port_priv.device->device_cap.support_bar_cq_ctrl ) {
  60. cq_uar.dword[0] = cpu_to_be32((port->eth_cq->next_idx & ARM_CQ_UAR_CQ_CI_MASK) |
  61. ((port->cmdsn++ & ARM_CQ_UAR_CMDSN_MASK) << ARM_CQ_UAR_CMDSN_OFFSET));
  62. cq_uar.dword[1] = cpu_to_be32(port->eth_cq->cqn);
  63. wmb();
  64. writeq(cq_uar.qword, port->port_priv.device->uar.virt + ARM_CQ_UAR_CQ_CI_OFFSET);
  65. port->port_priv.arm_cq_doorbell_record->dword[0] = cq_uar.dword[1];
  66. port->port_priv.arm_cq_doorbell_record->dword[1] = cq_uar.dword[0];
  67. } else {
  68. val32 = ( port->eth_cq->next_idx & 0xffffff );
  69. if ( nodnic_port_set ( & port->port_priv, nodnic_port_option_arm_cq, val32 ) ) {
  70. MLX_DEBUG_ERROR( port->port_priv.device, "Failed to arm the CQ\n" );
  71. return MLX_FAILED;
  72. }
  73. }
  74. #else
  75. mlx_utils *utils = port->port_priv.device->utils;
  76. nodnic_port_data_flow_gw *ptr = port->port_priv.data_flow_gw;
  77. mlx_uint32 data = 0;
  78. mlx_uint32 val = 0;
  79. if ( port->port_priv.device->device_cap.crspace_doorbells == 0 ) {
  80. val = ( port->eth_cq->next_idx & 0xffff );
  81. if ( nodnic_port_set ( & port->port_priv, nodnic_port_option_arm_cq, val ) ) {
  82. MLX_DEBUG_ERROR( port->port_priv.device, "Failed to arm the CQ\n" );
  83. return MLX_FAILED;
  84. }
  85. } else {
  86. /* Arming the CQ with CQ CI should be with this format -
  87. * 16 bit - CQ CI - same endianness as the FW (don't swap bytes)
  88. * 15 bit - reserved
  89. * 1 bit - arm CQ - must correct the endianness with the reserved above */
  90. data = ( ( ( port->eth_cq->next_idx & 0xffff ) << 16 ) | 0x0080 );
  91. /* Write the new index and update FW that new data was submitted */
  92. mlx_pci_mem_write ( utils, MlxPciWidthUint32, 0,
  93. ( mlx_uintn ) & ( ptr->armcq_cq_ci_dword ), 1, &data );
  94. }
  95. #endif
  96. return 0;
  97. }
  98. /**
  99. * Create completion queue
  100. *
  101. * @v ibdev Infiniband device
  102. * @v cq Completion queue
  103. * @ret rc Return status code
  104. */
  105. static int flexboot_nodnic_create_cq ( struct ib_device *ibdev ,
  106. struct ib_completion_queue *cq ) {
  107. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  108. struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1];
  109. struct flexboot_nodnic_completion_queue *flexboot_nodnic_cq;
  110. mlx_status status = MLX_SUCCESS;
  111. mlx_uint32 cqn;
  112. flexboot_nodnic_cq = (struct flexboot_nodnic_completion_queue *)
  113. zalloc(sizeof(*flexboot_nodnic_cq));
  114. if ( flexboot_nodnic_cq == NULL ) {
  115. status = MLX_OUT_OF_RESOURCES;
  116. goto qp_alloc_err;
  117. }
  118. status = nodnic_port_create_cq(&port->port_priv,
  119. cq->num_cqes *
  120. flexboot_nodnic->callbacks->get_cqe_size(),
  121. &flexboot_nodnic_cq->nodnic_completion_queue
  122. );
  123. MLX_FATAL_CHECK_STATUS(status, create_err,
  124. "nodnic_port_create_cq failed");
  125. flexboot_nodnic->callbacks->cqe_set_owner(
  126. flexboot_nodnic_cq->nodnic_completion_queue->cq_virt,
  127. cq->num_cqes);
  128. if ( flexboot_nodnic->device_priv.device_cap.support_bar_cq_ctrl ) {
  129. status = nodnic_port_query(&port->port_priv,
  130. nodnic_port_option_cq_n_index,
  131. (mlx_uint32 *)&cqn );
  132. MLX_FATAL_CHECK_STATUS(status, read_cqn_err,
  133. "failed to query cqn");
  134. cq->cqn = cqn;
  135. }
  136. ib_cq_set_drvdata ( cq, flexboot_nodnic_cq );
  137. return status;
  138. read_cqn_err:
  139. create_err:
  140. free(flexboot_nodnic_cq);
  141. qp_alloc_err:
  142. return status;
  143. }
  144. /**
  145. * Destroy completion queue
  146. *
  147. * @v ibdev Infiniband device
  148. * @v cq Completion queue
  149. */
  150. static void flexboot_nodnic_destroy_cq ( struct ib_device *ibdev ,
  151. struct ib_completion_queue *cq ) {
  152. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  153. struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1];
  154. struct flexboot_nodnic_completion_queue *flexboot_nodnic_cq = ib_cq_get_drvdata ( cq );
  155. nodnic_port_destroy_cq(&port->port_priv,
  156. flexboot_nodnic_cq->nodnic_completion_queue);
  157. free(flexboot_nodnic_cq);
  158. }
  159. static
  160. struct ib_work_queue * flexboot_nodnic_find_wq ( struct ib_device *ibdev ,
  161. struct ib_completion_queue *cq,
  162. unsigned long qpn, int is_send ) {
  163. struct ib_work_queue *wq;
  164. struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp;
  165. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  166. struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1];
  167. struct nodnic_ring *ring;
  168. mlx_uint32 out_qpn;
  169. list_for_each_entry ( wq, &cq->work_queues, list ) {
  170. flexboot_nodnic_qp = ib_qp_get_drvdata ( wq->qp );
  171. if( wq->is_send == is_send && wq->is_send == TRUE ) {
  172. ring = &flexboot_nodnic_qp->nodnic_queue_pair->send.nodnic_ring;
  173. } else if( wq->is_send == is_send && wq->is_send == FALSE ) {
  174. ring = &flexboot_nodnic_qp->nodnic_queue_pair->receive.nodnic_ring;
  175. } else {
  176. continue;
  177. }
  178. nodnic_port_get_qpn(&port->port_priv, ring, &out_qpn);
  179. if ( out_qpn == qpn )
  180. return wq;
  181. }
  182. return NULL;
  183. }
  184. /**
  185. * Handle completion
  186. *
  187. * @v ibdev Infiniband device
  188. * @v cq Completion queue
  189. * @v cqe Hardware completion queue entry
  190. * @ret rc Return status code
  191. */
  192. static int flexboot_nodnic_complete ( struct ib_device *ibdev,
  193. struct ib_completion_queue *cq,
  194. struct cqe_data *cqe_data ) {
  195. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  196. struct ib_work_queue *wq;
  197. struct ib_queue_pair *qp;
  198. struct io_buffer *iobuf;
  199. struct ib_address_vector recv_dest;
  200. struct ib_address_vector recv_source;
  201. unsigned long qpn;
  202. unsigned long wqe_idx;
  203. unsigned long wqe_idx_mask;
  204. size_t len;
  205. int rc = 0;
  206. /* Parse completion */
  207. qpn = cqe_data->qpn;
  208. if ( cqe_data->is_error == TRUE ) {
  209. DBGC ( flexboot_nodnic, "flexboot_nodnic %p CQN %#lx syndrome %x vendor %x\n",
  210. flexboot_nodnic, cq->cqn, cqe_data->syndrome,
  211. cqe_data->vendor_err_syndrome );
  212. rc = -EIO;
  213. /* Don't return immediately; propagate error to completer */
  214. }
  215. /* Identify work queue */
  216. wq = flexboot_nodnic_find_wq( ibdev, cq, qpn, cqe_data->is_send );
  217. if ( wq == NULL ) {
  218. DBGC ( flexboot_nodnic,
  219. "flexboot_nodnic %p CQN %#lx unknown %s QPN %#lx\n",
  220. flexboot_nodnic, cq->cqn,
  221. ( cqe_data->is_send ? "send" : "recv" ), qpn );
  222. return -EIO;
  223. }
  224. qp = wq->qp;
  225. /* Identify work queue entry */
  226. wqe_idx = cqe_data->wqe_counter;
  227. wqe_idx_mask = ( wq->num_wqes - 1 );
  228. DBGCP ( flexboot_nodnic,
  229. "NODNIC %p CQN %#lx QPN %#lx %s WQE %#lx completed:\n",
  230. flexboot_nodnic, cq->cqn, qp->qpn,
  231. ( cqe_data->is_send ? "send" : "recv" ),
  232. wqe_idx );
  233. /* Identify I/O buffer */
  234. iobuf = wq->iobufs[wqe_idx & wqe_idx_mask];
  235. if ( iobuf == NULL ) {
  236. DBGC ( flexboot_nodnic,
  237. "NODNIC %p CQN %#lx QPN %#lx empty %s WQE %#lx\n",
  238. flexboot_nodnic, cq->cqn, qp->qpn,
  239. ( cqe_data->is_send ? "send" : "recv" ), wqe_idx );
  240. return -EIO;
  241. }
  242. wq->iobufs[wqe_idx & wqe_idx_mask] = NULL;
  243. if ( cqe_data->is_send == TRUE ) {
  244. /* Hand off to completion handler */
  245. ib_complete_send ( ibdev, qp, iobuf, rc );
  246. } else if ( rc != 0 ) {
  247. /* Propagate error to receive completion handler */
  248. ib_complete_recv ( ibdev, qp, NULL, NULL, iobuf, rc );
  249. } else {
  250. /* Set received length */
  251. len = cqe_data->byte_cnt;
  252. assert ( len <= iob_tailroom ( iobuf ) );
  253. iob_put ( iobuf, len );
  254. memset ( &recv_dest, 0, sizeof ( recv_dest ) );
  255. recv_dest.qpn = qpn;
  256. memset ( &recv_source, 0, sizeof ( recv_source ) );
  257. switch ( qp->type ) {
  258. case IB_QPT_SMI:
  259. case IB_QPT_GSI:
  260. case IB_QPT_UD:
  261. case IB_QPT_RC:
  262. break;
  263. case IB_QPT_ETH:
  264. break;
  265. default:
  266. assert ( 0 );
  267. return -EINVAL;
  268. }
  269. /* Hand off to completion handler */
  270. ib_complete_recv ( ibdev, qp, &recv_dest,
  271. &recv_source, iobuf, rc );
  272. }
  273. return rc;
  274. }
  275. /**
  276. * Poll completion queue
  277. *
  278. * @v ibdev Infiniband device
  279. * @v cq Completion queues
  280. */
  281. static void flexboot_nodnic_poll_cq ( struct ib_device *ibdev,
  282. struct ib_completion_queue *cq) {
  283. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  284. struct flexboot_nodnic_completion_queue *flexboot_nodnic_cq = ib_cq_get_drvdata ( cq );
  285. void *cqe;
  286. mlx_size cqe_size;
  287. struct cqe_data cqe_data;
  288. unsigned int cqe_idx_mask;
  289. int rc;
  290. cqe_size = flexboot_nodnic->callbacks->get_cqe_size();
  291. while ( TRUE ) {
  292. /* Look for completion entry */
  293. cqe_idx_mask = ( cq->num_cqes - 1 );
  294. cqe = ((uint8_t *)flexboot_nodnic_cq->nodnic_completion_queue->cq_virt) +
  295. cqe_size * (cq->next_idx & cqe_idx_mask);
  296. /* TODO: check fill_completion */
  297. flexboot_nodnic->callbacks->fill_completion(cqe, &cqe_data);
  298. if ( cqe_data.owner ^
  299. ( ( cq->next_idx & cq->num_cqes ) ? 1 : 0 ) ) {
  300. /* Entry still owned by hardware; end of poll */
  301. break;
  302. }
  303. /* Handle completion */
  304. rc = flexboot_nodnic_complete ( ibdev, cq, &cqe_data );
  305. if ( rc != 0 ) {
  306. DBGC ( flexboot_nodnic, "flexboot_nodnic %p CQN %#lx failed to complete: %s\n",
  307. flexboot_nodnic, cq->cqn, strerror ( rc ) );
  308. DBGC_HDA ( flexboot_nodnic, virt_to_phys ( cqe ),
  309. cqe, sizeof ( *cqe ) );
  310. }
  311. /* Update completion queue's index */
  312. cq->next_idx++;
  313. }
  314. }
  315. /***************************************************************************
  316. *
  317. * Queue pair operations
  318. *
  319. ***************************************************************************
  320. */
  321. /**
  322. * Create queue pair
  323. *
  324. * @v ibdev Infiniband device
  325. * @v qp Queue pair
  326. * @ret rc Return status code
  327. */
  328. static int flexboot_nodnic_create_qp ( struct ib_device *ibdev,
  329. struct ib_queue_pair *qp ) {
  330. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  331. struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1];
  332. struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp;
  333. mlx_status status = MLX_SUCCESS;
  334. flexboot_nodnic_qp = (struct flexboot_nodnic_queue_pair *)zalloc(sizeof(*flexboot_nodnic_qp));
  335. if ( flexboot_nodnic_qp == NULL ) {
  336. status = MLX_OUT_OF_RESOURCES;
  337. goto qp_alloc_err;
  338. }
  339. status = nodnic_port_create_qp(&port->port_priv, qp->type,
  340. qp->send.num_wqes * sizeof(struct nodnic_send_wqbb),
  341. qp->send.num_wqes,
  342. qp->recv.num_wqes * sizeof(struct nodnic_recv_wqe),
  343. qp->recv.num_wqes,
  344. &flexboot_nodnic_qp->nodnic_queue_pair);
  345. MLX_FATAL_CHECK_STATUS(status, create_err,
  346. "nodnic_port_create_qp failed");
  347. ib_qp_set_drvdata ( qp, flexboot_nodnic_qp );
  348. return status;
  349. create_err:
  350. free(flexboot_nodnic_qp);
  351. qp_alloc_err:
  352. return status;
  353. }
  354. /**
  355. * Modify queue pair
  356. *
  357. * @v ibdev Infiniband device
  358. * @v qp Queue pair
  359. * @ret rc Return status code
  360. */
  361. static int flexboot_nodnic_modify_qp ( struct ib_device *ibdev __unused,
  362. struct ib_queue_pair *qp __unused) {
  363. /*not needed*/
  364. return 0;
  365. }
  366. /**
  367. * Destroy queue pair
  368. *
  369. * @v ibdev Infiniband device
  370. * @v qp Queue pair
  371. */
  372. static void flexboot_nodnic_destroy_qp ( struct ib_device *ibdev,
  373. struct ib_queue_pair *qp ) {
  374. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  375. struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1];
  376. struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp = ib_qp_get_drvdata ( qp );
  377. nodnic_port_destroy_qp(&port->port_priv, qp->type,
  378. flexboot_nodnic_qp->nodnic_queue_pair);
  379. free(flexboot_nodnic_qp);
  380. }
  381. /***************************************************************************
  382. *
  383. * Work request operations
  384. *
  385. ***************************************************************************
  386. */
  387. /**
  388. * Post send work queue entry
  389. *
  390. * @v ibdev Infiniband device
  391. * @v qp Queue pair
  392. * @v av Address vector
  393. * @v iobuf I/O buffer
  394. * @ret rc Return status code
  395. */
  396. static int flexboot_nodnic_post_send ( struct ib_device *ibdev,
  397. struct ib_queue_pair *qp,
  398. struct ib_address_vector *av,
  399. struct io_buffer *iobuf) {
  400. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  401. struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp = ib_qp_get_drvdata ( qp );
  402. struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1];
  403. struct ib_work_queue *wq = &qp->send;
  404. struct nodnic_send_wqbb *wqbb;
  405. nodnic_qp *nodnic_qp = flexboot_nodnic_qp->nodnic_queue_pair;
  406. struct nodnic_send_ring *send_ring = &nodnic_qp->send;
  407. mlx_status status = MLX_SUCCESS;
  408. unsigned int wqe_idx_mask;
  409. unsigned long wqe_idx;
  410. if ( ( port->port_priv.dma_state == FALSE ) ||
  411. ( port->port_priv.port_state & NODNIC_PORT_DISABLING_DMA ) ) {
  412. DBGC ( flexboot_nodnic, "flexboot_nodnic DMA disabled\n");
  413. status = -ENETDOWN;
  414. goto post_send_done;
  415. }
  416. /* Allocate work queue entry */
  417. wqe_idx = wq->next_idx;
  418. wqe_idx_mask = ( wq->num_wqes - 1 );
  419. if ( wq->iobufs[wqe_idx & wqe_idx_mask] ) {
  420. DBGC ( flexboot_nodnic, "flexboot_nodnic %p QPN %#lx send queue full\n",
  421. flexboot_nodnic, qp->qpn );
  422. status = -ENOBUFS;
  423. goto post_send_done;
  424. }
  425. wqbb = &send_ring->wqe_virt[wqe_idx & wqe_idx_mask];
  426. wq->iobufs[wqe_idx & wqe_idx_mask] = iobuf;
  427. assert ( flexboot_nodnic->callbacks->
  428. fill_send_wqe[qp->type] != NULL );
  429. status = flexboot_nodnic->callbacks->
  430. fill_send_wqe[qp->type] ( ibdev, qp, av, iobuf,
  431. wqbb, wqe_idx );
  432. if ( status != 0 ) {
  433. DBGC ( flexboot_nodnic, "flexboot_nodnic %p QPN %#lx fill send wqe failed\n",
  434. flexboot_nodnic, qp->qpn );
  435. goto post_send_done;
  436. }
  437. wq->next_idx++;
  438. status = port->port_priv.send_doorbell ( &port->port_priv,
  439. &send_ring->nodnic_ring, ( mlx_uint16 ) wq->next_idx );
  440. if ( flexboot_nodnic->callbacks->tx_uar_send_doorbell_fn ) {
  441. flexboot_nodnic->callbacks->tx_uar_send_doorbell_fn ( ibdev, wqbb );
  442. }
  443. if ( status != 0 ) {
  444. DBGC ( flexboot_nodnic, "flexboot_nodnic %p ring send doorbell failed\n", flexboot_nodnic );
  445. }
  446. post_send_done:
  447. return status;
  448. }
  449. /**
  450. * Post receive work queue entry
  451. *
  452. * @v ibdev Infiniband device
  453. * @v qp Queue pair
  454. * @v iobuf I/O buffer
  455. * @ret rc Return status code
  456. */
  457. static int flexboot_nodnic_post_recv ( struct ib_device *ibdev,
  458. struct ib_queue_pair *qp,
  459. struct io_buffer *iobuf ) {
  460. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  461. struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp = ib_qp_get_drvdata ( qp );
  462. struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1];
  463. struct ib_work_queue *wq = &qp->recv;
  464. nodnic_qp *nodnic_qp = flexboot_nodnic_qp->nodnic_queue_pair;
  465. struct nodnic_recv_ring *recv_ring = &nodnic_qp->receive;
  466. struct nodnic_recv_wqe *wqe;
  467. unsigned int wqe_idx_mask;
  468. mlx_status status = MLX_SUCCESS;
  469. /* Allocate work queue entry */
  470. wqe_idx_mask = ( wq->num_wqes - 1 );
  471. if ( wq->iobufs[wq->next_idx & wqe_idx_mask] ) {
  472. DBGC ( flexboot_nodnic,
  473. "flexboot_nodnic %p QPN %#lx receive queue full\n",
  474. flexboot_nodnic, qp->qpn );
  475. status = -ENOBUFS;
  476. goto post_recv_done;
  477. }
  478. wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf;
  479. wqe = &((struct nodnic_recv_wqe*)recv_ring->wqe_virt)[wq->next_idx & wqe_idx_mask];
  480. MLX_FILL_1 ( &wqe->data[0], 0, byte_count, iob_tailroom ( iobuf ) );
  481. MLX_FILL_1 ( &wqe->data[0], 1, l_key, flexboot_nodnic->device_priv.lkey );
  482. MLX_FILL_H ( &wqe->data[0], 2,
  483. local_address_h, virt_to_bus ( iobuf->data ) );
  484. MLX_FILL_1 ( &wqe->data[0], 3,
  485. local_address_l, virt_to_bus ( iobuf->data ) );
  486. wq->next_idx++;
  487. status = port->port_priv.recv_doorbell ( &port->port_priv,
  488. &recv_ring->nodnic_ring, ( mlx_uint16 ) wq->next_idx );
  489. if ( status != 0 ) {
  490. DBGC ( flexboot_nodnic, "flexboot_nodnic %p ring receive doorbell failed\n", flexboot_nodnic );
  491. }
  492. post_recv_done:
  493. return status;
  494. }
  495. /***************************************************************************
  496. *
  497. * Event queues
  498. *
  499. ***************************************************************************
  500. */
  501. static void flexboot_nodnic_poll_eq ( struct ib_device *ibdev ) {
  502. struct flexboot_nodnic *flexboot_nodnic;
  503. struct flexboot_nodnic_port *port;
  504. struct net_device *netdev;
  505. nodnic_port_state state = 0;
  506. mlx_status status;
  507. if ( ! ibdev ) {
  508. DBG ( "%s: ibdev = NULL!!!\n", __FUNCTION__ );
  509. return;
  510. }
  511. flexboot_nodnic = ib_get_drvdata ( ibdev );
  512. port = &flexboot_nodnic->port[ibdev->port - 1];
  513. netdev = port->netdev;
  514. if ( ! netdev_is_open ( netdev ) ) {
  515. DBG2( "%s: port %d is closed\n", __FUNCTION__, port->ibdev->port );
  516. return;
  517. }
  518. /* we don't poll EQ. Just poll link status if it's not active */
  519. if ( ! netdev_link_ok ( netdev ) ) {
  520. status = nodnic_port_get_state ( &port->port_priv, &state );
  521. MLX_FATAL_CHECK_STATUS(status, state_err, "nodnic_port_get_state failed");
  522. if ( state == nodnic_port_state_active ) {
  523. DBG( "%s: port %d physical link is up\n", __FUNCTION__,
  524. port->ibdev->port );
  525. port->type->state_change ( flexboot_nodnic, port, 1 );
  526. }
  527. }
  528. state_err:
  529. return;
  530. }
  531. /***************************************************************************
  532. *
  533. * Multicast group operations
  534. *
  535. ***************************************************************************
  536. */
  537. static int flexboot_nodnic_mcast_attach ( struct ib_device *ibdev,
  538. struct ib_queue_pair *qp,
  539. union ib_gid *gid) {
  540. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  541. struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1];
  542. mlx_mac_address mac;
  543. mlx_status status = MLX_SUCCESS;
  544. switch (qp->type) {
  545. case IB_QPT_ETH:
  546. memcpy(&mac, &gid, sizeof(mac));
  547. status = nodnic_port_add_mac_filter(&port->port_priv, mac);
  548. MLX_CHECK_STATUS(flexboot_nodnic->device_priv, status, mac_err,
  549. "nodnic_port_add_mac_filter failed");
  550. break;
  551. default:
  552. break;
  553. }
  554. mac_err:
  555. return status;
  556. }
  557. static void flexboot_nodnic_mcast_detach ( struct ib_device *ibdev,
  558. struct ib_queue_pair *qp,
  559. union ib_gid *gid ) {
  560. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  561. struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1];
  562. mlx_mac_address mac;
  563. mlx_status status = MLX_SUCCESS;
  564. switch (qp->type) {
  565. case IB_QPT_ETH:
  566. memcpy(&mac, &gid, sizeof(mac));
  567. status = nodnic_port_remove_mac_filter(&port->port_priv, mac);
  568. MLX_CHECK_STATUS(flexboot_nodnic->device_priv, status, mac_err,
  569. "nodnic_port_remove_mac_filter failed");
  570. break;
  571. default:
  572. break;
  573. }
  574. mac_err:
  575. return;
  576. }
  577. /***************************************************************************
  578. *
  579. * Infiniband link-layer operations
  580. *
  581. ***************************************************************************
  582. */
  583. /**
  584. * Initialise Infiniband link
  585. *
  586. * @v ibdev Infiniband device
  587. * @ret rc Return status code
  588. */
  589. static int flexboot_nodnic_ib_open ( struct ib_device *ibdev __unused) {
  590. int rc = 0;
  591. /*TODO: add implementation*/
  592. return rc;
  593. }
  594. /**
  595. * Close Infiniband link
  596. *
  597. * @v ibdev Infiniband device
  598. */
  599. static void flexboot_nodnic_ib_close ( struct ib_device *ibdev __unused) {
  600. /*TODO: add implementation*/
  601. }
  602. /**
  603. * Inform embedded subnet management agent of a received MAD
  604. *
  605. * @v ibdev Infiniband device
  606. * @v mad MAD
  607. * @ret rc Return status code
  608. */
  609. static int flexboot_nodnic_inform_sma ( struct ib_device *ibdev __unused,
  610. union ib_mad *mad __unused) {
  611. /*TODO: add implementation*/
  612. return 0;
  613. }
  614. /** flexboot_nodnic Infiniband operations */
  615. static struct ib_device_operations flexboot_nodnic_ib_operations = {
  616. .create_cq = flexboot_nodnic_create_cq,
  617. .destroy_cq = flexboot_nodnic_destroy_cq,
  618. .create_qp = flexboot_nodnic_create_qp,
  619. .modify_qp = flexboot_nodnic_modify_qp,
  620. .destroy_qp = flexboot_nodnic_destroy_qp,
  621. .post_send = flexboot_nodnic_post_send,
  622. .post_recv = flexboot_nodnic_post_recv,
  623. .poll_cq = flexboot_nodnic_poll_cq,
  624. .poll_eq = flexboot_nodnic_poll_eq,
  625. .open = flexboot_nodnic_ib_open,
  626. .close = flexboot_nodnic_ib_close,
  627. .mcast_attach = flexboot_nodnic_mcast_attach,
  628. .mcast_detach = flexboot_nodnic_mcast_detach,
  629. .set_port_info = flexboot_nodnic_inform_sma,
  630. .set_pkey_table = flexboot_nodnic_inform_sma,
  631. };
  632. /***************************************************************************
  633. *
  634. *
  635. *
  636. ***************************************************************************
  637. */
  638. #define FLEX_NODNIC_TX_POLL_TOUT 500000
  639. #define FLEX_NODNIC_TX_POLL_USLEEP 10
  640. static void flexboot_nodnic_complete_all_tx ( struct flexboot_nodnic_port *port ) {
  641. struct ib_device *ibdev = port->ibdev;
  642. struct ib_completion_queue *cq;
  643. struct ib_work_queue *wq;
  644. int keep_polling = 0;
  645. int timeout = FLEX_NODNIC_TX_POLL_TOUT;
  646. list_for_each_entry ( cq, &ibdev->cqs, list ) {
  647. do {
  648. ib_poll_cq ( ibdev, cq );
  649. keep_polling = 0;
  650. list_for_each_entry ( wq, &cq->work_queues, list ) {
  651. if ( wq->is_send )
  652. keep_polling += ( wq->fill > 0 );
  653. }
  654. udelay ( FLEX_NODNIC_TX_POLL_USLEEP );
  655. } while ( keep_polling && ( timeout-- > 0 ) );
  656. }
  657. }
  658. static void flexboot_nodnic_port_disable_dma ( struct flexboot_nodnic_port *port ) {
  659. nodnic_port_priv *port_priv = & ( port->port_priv );
  660. mlx_status status;
  661. if ( ! ( port_priv->port_state & NODNIC_PORT_OPENED ) )
  662. return;
  663. port_priv->port_state |= NODNIC_PORT_DISABLING_DMA;
  664. flexboot_nodnic_complete_all_tx ( port );
  665. if ( ( status = nodnic_port_disable_dma ( port_priv ) ) ) {
  666. MLX_DEBUG_WARN ( port, "Failed to disable DMA %d\n", status );
  667. }
  668. port_priv->port_state &= ~NODNIC_PORT_DISABLING_DMA;
  669. }
  670. /***************************************************************************
  671. *
  672. * Ethernet operation
  673. *
  674. ***************************************************************************
  675. */
  676. /** Number of flexboot_nodnic Ethernet send work queue entries */
  677. #define FLEXBOOT_NODNIC_ETH_NUM_SEND_WQES 64
  678. /** Number of flexboot_nodnic Ethernet receive work queue entries */
  679. #define FLEXBOOT_NODNIC_ETH_NUM_RECV_WQES 64
  680. /** flexboot nodnic Ethernet queue pair operations */
  681. static struct ib_queue_pair_operations flexboot_nodnic_eth_qp_op = {
  682. .alloc_iob = alloc_iob,
  683. };
  684. /**
  685. * Transmit packet via flexboot_nodnic Ethernet device
  686. *
  687. * @v netdev Network device
  688. * @v iobuf I/O buffer
  689. * @ret rc Return status code
  690. */
  691. static int flexboot_nodnic_eth_transmit ( struct net_device *netdev,
  692. struct io_buffer *iobuf) {
  693. struct flexboot_nodnic_port *port = netdev->priv;
  694. struct ib_device *ibdev = port->ibdev;
  695. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  696. int rc;
  697. rc = ib_post_send ( ibdev, port->eth_qp, NULL, iobuf);
  698. /* Transmit packet */
  699. if ( rc != 0) {
  700. DBGC ( flexboot_nodnic, "NODNIC %p port %d could not transmit: %s\n",
  701. flexboot_nodnic, ibdev->port, strerror ( rc ) );
  702. return rc;
  703. }
  704. return 0;
  705. }
  706. /**
  707. * Handle flexboot_nodnic Ethernet device send completion
  708. *
  709. * @v ibdev Infiniband device
  710. * @v qp Queue pair
  711. * @v iobuf I/O buffer
  712. * @v rc Completion status code
  713. */
  714. static void flexboot_nodnic_eth_complete_send ( struct ib_device *ibdev __unused,
  715. struct ib_queue_pair *qp,
  716. struct io_buffer *iobuf,
  717. int rc) {
  718. struct net_device *netdev = ib_qp_get_ownerdata ( qp );
  719. netdev_tx_complete_err ( netdev, iobuf, rc );
  720. }
  721. /**
  722. * Handle flexboot_nodnic Ethernet device receive completion
  723. *
  724. * @v ibdev Infiniband device
  725. * @v qp Queue pair
  726. * @v av Address vector, or NULL
  727. * @v iobuf I/O buffer
  728. * @v rc Completion status code
  729. */
  730. static void flexboot_nodnic_eth_complete_recv ( struct ib_device *ibdev __unused,
  731. struct ib_queue_pair *qp,
  732. struct ib_address_vector *dest __unused,
  733. struct ib_address_vector *source,
  734. struct io_buffer *iobuf,
  735. int rc) {
  736. struct net_device *netdev = ib_qp_get_ownerdata ( qp );
  737. if ( rc != 0 ) {
  738. DBG ( "Received packet with error\n" );
  739. netdev_rx_err ( netdev, iobuf, rc );
  740. return;
  741. }
  742. if ( source == NULL ) {
  743. DBG ( "Received packet without address vector\n" );
  744. netdev_rx_err ( netdev, iobuf, -ENOTTY );
  745. return;
  746. }
  747. netdev_rx ( netdev, iobuf );
  748. }
  749. /** flexboot_nodnic Ethernet device completion operations */
  750. static struct ib_completion_queue_operations flexboot_nodnic_eth_cq_op = {
  751. .complete_send = flexboot_nodnic_eth_complete_send,
  752. .complete_recv = flexboot_nodnic_eth_complete_recv,
  753. };
  754. /**
  755. * Poll flexboot_nodnic Ethernet device
  756. *
  757. * @v netdev Network device
  758. */
  759. static void flexboot_nodnic_eth_poll ( struct net_device *netdev) {
  760. struct flexboot_nodnic_port *port = netdev->priv;
  761. struct ib_device *ibdev = port->ibdev;
  762. ib_poll_eq ( ibdev );
  763. }
  764. /**
  765. * Open flexboot_nodnic Ethernet device
  766. *
  767. * @v netdev Network device
  768. * @ret rc Return status code
  769. */
  770. static int flexboot_nodnic_eth_open ( struct net_device *netdev ) {
  771. struct flexboot_nodnic_port *port = netdev->priv;
  772. struct ib_device *ibdev = port->ibdev;
  773. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  774. mlx_status status = MLX_SUCCESS;
  775. struct ib_completion_queue *dummy_cq = NULL;
  776. struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp = NULL;
  777. mlx_uint64 cq_size = 0;
  778. mlx_uint32 qpn = 0;
  779. nodnic_port_state state = nodnic_port_state_down;
  780. if ( port->port_priv.port_state & NODNIC_PORT_OPENED ) {
  781. DBGC ( flexboot_nodnic, "%s: port %d is already opened\n",
  782. __FUNCTION__, port->ibdev->port );
  783. return 0;
  784. }
  785. port->port_priv.port_state |= NODNIC_PORT_OPENED;
  786. dummy_cq = zalloc ( sizeof ( struct ib_completion_queue ) );
  787. if ( dummy_cq == NULL ) {
  788. DBGC ( flexboot_nodnic, "%s: Failed to allocate dummy CQ\n", __FUNCTION__ );
  789. status = MLX_OUT_OF_RESOURCES;
  790. goto err_create_dummy_cq;
  791. }
  792. INIT_LIST_HEAD ( &dummy_cq->work_queues );
  793. port->eth_qp = ib_create_qp ( ibdev, IB_QPT_ETH,
  794. FLEXBOOT_NODNIC_ETH_NUM_SEND_WQES, dummy_cq,
  795. FLEXBOOT_NODNIC_ETH_NUM_RECV_WQES, dummy_cq,
  796. &flexboot_nodnic_eth_qp_op, netdev->name );
  797. if ( !port->eth_qp ) {
  798. DBGC ( flexboot_nodnic, "flexboot_nodnic %p port %d could not create queue pair\n",
  799. flexboot_nodnic, ibdev->port );
  800. status = MLX_OUT_OF_RESOURCES;
  801. goto err_create_qp;
  802. }
  803. ib_qp_set_ownerdata ( port->eth_qp, netdev );
  804. status = nodnic_port_get_cq_size(&port->port_priv, &cq_size);
  805. MLX_FATAL_CHECK_STATUS(status, get_cq_size_err,
  806. "nodnic_port_get_cq_size failed");
  807. port->eth_cq = ib_create_cq ( ibdev, cq_size,
  808. &flexboot_nodnic_eth_cq_op );
  809. if ( !port->eth_cq ) {
  810. DBGC ( flexboot_nodnic,
  811. "flexboot_nodnic %p port %d could not create completion queue\n",
  812. flexboot_nodnic, ibdev->port );
  813. status = MLX_OUT_OF_RESOURCES;
  814. goto err_create_cq;
  815. }
  816. port->eth_qp->send.cq = port->eth_cq;
  817. list_del(&port->eth_qp->send.list);
  818. list_add ( &port->eth_qp->send.list, &port->eth_cq->work_queues );
  819. port->eth_qp->recv.cq = port->eth_cq;
  820. list_del(&port->eth_qp->recv.list);
  821. list_add ( &port->eth_qp->recv.list, &port->eth_cq->work_queues );
  822. status = nodnic_port_allocate_eq(&port->port_priv,
  823. flexboot_nodnic->device_priv.device_cap.log_working_buffer_size);
  824. MLX_FATAL_CHECK_STATUS(status, eq_alloc_err,
  825. "nodnic_port_allocate_eq failed");
  826. status = nodnic_port_init(&port->port_priv);
  827. MLX_FATAL_CHECK_STATUS(status, init_err,
  828. "nodnic_port_init failed");
  829. /* update qp - qpn */
  830. flexboot_nodnic_qp = ib_qp_get_drvdata ( port->eth_qp );
  831. status = nodnic_port_get_qpn(&port->port_priv,
  832. &flexboot_nodnic_qp->nodnic_queue_pair->send.nodnic_ring,
  833. &qpn);
  834. MLX_FATAL_CHECK_STATUS(status, qpn_err,
  835. "nodnic_port_get_qpn failed");
  836. port->eth_qp->qpn = qpn;
  837. /* Fill receive rings */
  838. ib_refill_recv ( ibdev, port->eth_qp );
  839. status = nodnic_port_enable_dma(&port->port_priv);
  840. MLX_FATAL_CHECK_STATUS(status, dma_err,
  841. "nodnic_port_enable_dma failed");
  842. if (flexboot_nodnic->device_priv.device_cap.support_promisc_filter) {
  843. status = nodnic_port_set_promisc(&port->port_priv, TRUE);
  844. MLX_FATAL_CHECK_STATUS(status, promisc_err,
  845. "nodnic_port_set_promisc failed");
  846. }
  847. status = nodnic_port_get_state(&port->port_priv, &state);
  848. MLX_FATAL_CHECK_STATUS(status, state_err,
  849. "nodnic_port_get_state failed");
  850. port->type->state_change (
  851. flexboot_nodnic, port, state == nodnic_port_state_active );
  852. DBGC ( flexboot_nodnic, "%s: port %d opened (link is %s)\n",
  853. __FUNCTION__, port->ibdev->port,
  854. ( ( state == nodnic_port_state_active ) ? "Up" : "Down" ) );
  855. free(dummy_cq);
  856. return 0;
  857. state_err:
  858. promisc_err:
  859. dma_err:
  860. qpn_err:
  861. nodnic_port_close(&port->port_priv);
  862. init_err:
  863. nodnic_port_free_eq(&port->port_priv);
  864. eq_alloc_err:
  865. err_create_cq:
  866. get_cq_size_err:
  867. ib_destroy_qp(ibdev, port->eth_qp );
  868. err_create_qp:
  869. free(dummy_cq);
  870. err_create_dummy_cq:
  871. port->port_priv.port_state &= ~NODNIC_PORT_OPENED;
  872. return status;
  873. }
  874. /**
  875. * Close flexboot_nodnic Ethernet device
  876. *
  877. * @v netdev Network device
  878. */
  879. static void flexboot_nodnic_eth_close ( struct net_device *netdev) {
  880. struct flexboot_nodnic_port *port = netdev->priv;
  881. struct ib_device *ibdev = port->ibdev;
  882. struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev );
  883. mlx_status status = MLX_SUCCESS;
  884. if ( ! ( port->port_priv.port_state & NODNIC_PORT_OPENED ) ) {
  885. DBGC ( flexboot_nodnic, "%s: port %d is already closed\n",
  886. __FUNCTION__, port->ibdev->port );
  887. return;
  888. }
  889. if (flexboot_nodnic->device_priv.device_cap.support_promisc_filter) {
  890. if ( ( status = nodnic_port_set_promisc( &port->port_priv, FALSE ) ) ) {
  891. DBGC ( flexboot_nodnic,
  892. "nodnic_port_set_promisc failed (status = %d)\n", status );
  893. }
  894. }
  895. flexboot_nodnic_port_disable_dma ( port );
  896. port->port_priv.port_state &= ~NODNIC_PORT_OPENED;
  897. port->type->state_change ( flexboot_nodnic, port, FALSE );
  898. /* Close port */
  899. status = nodnic_port_close(&port->port_priv);
  900. if ( status != MLX_SUCCESS ) {
  901. DBGC ( flexboot_nodnic, "flexboot_nodnic %p port %d could not close port: %s\n",
  902. flexboot_nodnic, ibdev->port, strerror ( status ) );
  903. /* Nothing we can do about this */
  904. }
  905. ib_destroy_qp ( ibdev, port->eth_qp );
  906. port->eth_qp = NULL;
  907. ib_destroy_cq ( ibdev, port->eth_cq );
  908. port->eth_cq = NULL;
  909. nodnic_port_free_eq(&port->port_priv);
  910. DBGC ( flexboot_nodnic, "%s: port %d closed\n", __FUNCTION__, port->ibdev->port );
  911. }
  912. void flexboot_nodnic_eth_irq ( struct net_device *netdev, int enable ) {
  913. struct flexboot_nodnic_port *port = netdev->priv;
  914. if ( enable ) {
  915. if ( ( port->port_priv.port_state & NODNIC_PORT_OPENED ) &&
  916. ! ( port->port_priv.port_state & NODNIC_PORT_DISABLING_DMA ) ) {
  917. flexboot_nodnic_arm_cq ( port );
  918. } else {
  919. /* do nothing */
  920. }
  921. } else {
  922. nodnic_device_clear_int( port->port_priv.device );
  923. }
  924. }
  925. /** flexboot_nodnic Ethernet network device operations */
  926. static struct net_device_operations flexboot_nodnic_eth_operations = {
  927. .open = flexboot_nodnic_eth_open,
  928. .close = flexboot_nodnic_eth_close,
  929. .transmit = flexboot_nodnic_eth_transmit,
  930. .poll = flexboot_nodnic_eth_poll,
  931. };
  932. /**
  933. * Register flexboot_nodnic Ethernet device
  934. */
  935. static int flexboot_nodnic_register_netdev ( struct flexboot_nodnic *flexboot_nodnic,
  936. struct flexboot_nodnic_port *port) {
  937. mlx_status status = MLX_SUCCESS;
  938. struct net_device *netdev;
  939. struct ib_device *ibdev = port->ibdev;
  940. union {
  941. uint8_t bytes[8];
  942. uint32_t dwords[2];
  943. } mac;
  944. /* Allocate network devices */
  945. netdev = alloc_etherdev ( 0 );
  946. if ( netdev == NULL ) {
  947. DBGC ( flexboot_nodnic, "flexboot_nodnic %p port %d could not allocate net device\n",
  948. flexboot_nodnic, ibdev->port );
  949. status = MLX_OUT_OF_RESOURCES;
  950. goto alloc_err;
  951. }
  952. port->netdev = netdev;
  953. netdev_init ( netdev, &flexboot_nodnic_eth_operations );
  954. netdev->dev = ibdev->dev;
  955. netdev->priv = port;
  956. status = nodnic_port_query(&port->port_priv,
  957. nodnic_port_option_mac_high,
  958. &mac.dwords[0]);
  959. MLX_FATAL_CHECK_STATUS(status, mac_err,
  960. "failed to query mac high");
  961. status = nodnic_port_query(&port->port_priv,
  962. nodnic_port_option_mac_low,
  963. &mac.dwords[1]);
  964. MLX_FATAL_CHECK_STATUS(status, mac_err,
  965. "failed to query mac low");
  966. mac.dwords[0] = htonl(mac.dwords[0]);
  967. mac.dwords[1] = htonl(mac.dwords[1]);
  968. memcpy ( netdev->hw_addr,
  969. &mac.bytes[2], ETH_ALEN);
  970. /* Register network device */
  971. status = register_netdev ( netdev );
  972. if ( status != MLX_SUCCESS ) {
  973. DBGC ( flexboot_nodnic,
  974. "flexboot_nodnic %p port %d could not register network device: %s\n",
  975. flexboot_nodnic, ibdev->port, strerror ( status ) );
  976. goto reg_err;
  977. }
  978. return status;
  979. reg_err:
  980. mac_err:
  981. netdev_put ( netdev );
  982. alloc_err:
  983. return status;
  984. }
  985. /**
  986. * Handle flexboot_nodnic Ethernet device port state change
  987. */
  988. static void flexboot_nodnic_state_change_netdev ( struct flexboot_nodnic *flexboot_nodnic __unused,
  989. struct flexboot_nodnic_port *port,
  990. int link_up ) {
  991. struct net_device *netdev = port->netdev;
  992. if ( link_up )
  993. netdev_link_up ( netdev );
  994. else
  995. netdev_link_down ( netdev );
  996. }
  997. /**
  998. * Unregister flexboot_nodnic Ethernet device
  999. */
  1000. static void flexboot_nodnic_unregister_netdev ( struct flexboot_nodnic *flexboot_nodnic __unused,
  1001. struct flexboot_nodnic_port *port ) {
  1002. struct net_device *netdev = port->netdev;
  1003. unregister_netdev ( netdev );
  1004. netdev_nullify ( netdev );
  1005. netdev_put ( netdev );
  1006. }
  1007. /** flexboot_nodnic Ethernet port type */
  1008. static struct flexboot_nodnic_port_type flexboot_nodnic_port_type_eth = {
  1009. .register_dev = flexboot_nodnic_register_netdev,
  1010. .state_change = flexboot_nodnic_state_change_netdev,
  1011. .unregister_dev = flexboot_nodnic_unregister_netdev,
  1012. };
  1013. /***************************************************************************
  1014. *
  1015. * PCI interface helper functions
  1016. *
  1017. ***************************************************************************
  1018. */
  1019. static
  1020. mlx_status
  1021. flexboot_nodnic_allocate_infiniband_devices( struct flexboot_nodnic *flexboot_nodnic_priv ) {
  1022. mlx_status status = MLX_SUCCESS;
  1023. nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv;
  1024. struct pci_device *pci = flexboot_nodnic_priv->pci;
  1025. struct ib_device *ibdev = NULL;
  1026. unsigned int i = 0;
  1027. /* Allocate Infiniband devices */
  1028. for (; i < device_priv->device_cap.num_ports; i++) {
  1029. if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) )
  1030. continue;
  1031. ibdev = alloc_ibdev(0);
  1032. if (ibdev == NULL) {
  1033. status = MLX_OUT_OF_RESOURCES;
  1034. goto err_alloc_ibdev;
  1035. }
  1036. flexboot_nodnic_priv->port[i].ibdev = ibdev;
  1037. ibdev->op = &flexboot_nodnic_ib_operations;
  1038. ibdev->dev = &pci->dev;
  1039. ibdev->port = ( FLEXBOOT_NODNIC_PORT_BASE + i);
  1040. ib_set_drvdata(ibdev, flexboot_nodnic_priv);
  1041. }
  1042. return status;
  1043. err_alloc_ibdev:
  1044. for ( i-- ; ( signed int ) i >= 0 ; i-- )
  1045. ibdev_put ( flexboot_nodnic_priv->port[i].ibdev );
  1046. return status;
  1047. }
  1048. static
  1049. mlx_status
  1050. flexboot_nodnic_thin_init_ports( struct flexboot_nodnic *flexboot_nodnic_priv ) {
  1051. mlx_status status = MLX_SUCCESS;
  1052. nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv;
  1053. nodnic_port_priv *port_priv = NULL;
  1054. unsigned int i = 0;
  1055. for ( i = 0; i < device_priv->device_cap.num_ports; i++ ) {
  1056. if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) )
  1057. continue;
  1058. port_priv = &flexboot_nodnic_priv->port[i].port_priv;
  1059. status = nodnic_port_thin_init( device_priv, port_priv, i );
  1060. MLX_FATAL_CHECK_STATUS(status, thin_init_err,
  1061. "flexboot_nodnic_thin_init_ports failed");
  1062. }
  1063. thin_init_err:
  1064. return status;
  1065. }
  1066. static
  1067. mlx_status
  1068. flexboot_nodnic_set_ports_type ( struct flexboot_nodnic *flexboot_nodnic_priv ) {
  1069. mlx_status status = MLX_SUCCESS;
  1070. nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv;
  1071. nodnic_port_priv *port_priv = NULL;
  1072. nodnic_port_type type = NODNIC_PORT_TYPE_UNKNOWN;
  1073. unsigned int i = 0;
  1074. for ( i = 0 ; i < device_priv->device_cap.num_ports ; i++ ) {
  1075. if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) )
  1076. continue;
  1077. port_priv = &flexboot_nodnic_priv->port[i].port_priv;
  1078. status = nodnic_port_get_type(port_priv, &type);
  1079. MLX_FATAL_CHECK_STATUS(status, type_err,
  1080. "nodnic_port_get_type failed");
  1081. switch ( type ) {
  1082. case NODNIC_PORT_TYPE_ETH:
  1083. DBGC ( flexboot_nodnic_priv, "Port %d type is Ethernet\n", i );
  1084. flexboot_nodnic_priv->port[i].type = &flexboot_nodnic_port_type_eth;
  1085. break;
  1086. case NODNIC_PORT_TYPE_IB:
  1087. DBGC ( flexboot_nodnic_priv, "Port %d type is Infiniband\n", i );
  1088. status = MLX_UNSUPPORTED;
  1089. goto type_err;
  1090. default:
  1091. DBGC ( flexboot_nodnic_priv, "Port %d type is unknown\n", i );
  1092. status = MLX_UNSUPPORTED;
  1093. goto type_err;
  1094. }
  1095. }
  1096. type_err:
  1097. return status;
  1098. }
  1099. static
  1100. mlx_status
  1101. flexboot_nodnic_ports_register_dev( struct flexboot_nodnic *flexboot_nodnic_priv ) {
  1102. mlx_status status = MLX_SUCCESS;
  1103. nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv;
  1104. struct flexboot_nodnic_port *port = NULL;
  1105. unsigned int i = 0;
  1106. for (; i < device_priv->device_cap.num_ports; i++) {
  1107. if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) )
  1108. continue;
  1109. port = &flexboot_nodnic_priv->port[i];
  1110. status = port->type->register_dev ( flexboot_nodnic_priv, port );
  1111. MLX_FATAL_CHECK_STATUS(status, reg_err,
  1112. "port register_dev failed");
  1113. }
  1114. reg_err:
  1115. return status;
  1116. }
  1117. static
  1118. mlx_status
  1119. flexboot_nodnic_ports_unregister_dev ( struct flexboot_nodnic *flexboot_nodnic_priv ) {
  1120. struct flexboot_nodnic_port *port;
  1121. nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv;
  1122. int i = (device_priv->device_cap.num_ports - 1);
  1123. for (; i >= 0; i--) {
  1124. if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) )
  1125. continue;
  1126. port = &flexboot_nodnic_priv->port[i];
  1127. port->type->unregister_dev(flexboot_nodnic_priv, port);
  1128. ibdev_put(flexboot_nodnic_priv->port[i].ibdev);
  1129. }
  1130. return MLX_SUCCESS;
  1131. }
  1132. /***************************************************************************
  1133. *
  1134. * flexboot nodnic interface
  1135. *
  1136. ***************************************************************************
  1137. */
  1138. __unused static void flexboot_nodnic_enable_dma ( struct flexboot_nodnic *nodnic ) {
  1139. nodnic_port_priv *port_priv;
  1140. mlx_status status;
  1141. int i;
  1142. for ( i = 0; i < nodnic->device_priv.device_cap.num_ports; i++ ) {
  1143. if ( ! ( nodnic->port_mask & ( i + 1 ) ) )
  1144. continue;
  1145. port_priv = & ( nodnic->port[i].port_priv );
  1146. if ( ! ( port_priv->port_state & NODNIC_PORT_OPENED ) )
  1147. continue;
  1148. if ( ( status = nodnic_port_enable_dma ( port_priv ) ) ) {
  1149. MLX_DEBUG_WARN ( nodnic, "Failed to enable DMA %d\n", status );
  1150. }
  1151. }
  1152. }
  1153. __unused static void flexboot_nodnic_disable_dma ( struct flexboot_nodnic *nodnic ) {
  1154. int i;
  1155. for ( i = 0; i < nodnic->device_priv.device_cap.num_ports; i++ ) {
  1156. if ( ! ( nodnic->port_mask & ( i + 1 ) ) )
  1157. continue;
  1158. flexboot_nodnic_port_disable_dma ( & ( nodnic->port[i] ) );
  1159. }
  1160. }
  1161. int flexboot_nodnic_is_supported ( struct pci_device *pci ) {
  1162. mlx_utils utils;
  1163. mlx_pci_gw_buffer buffer;
  1164. mlx_status status;
  1165. int is_supported = 0;
  1166. DBG ( "%s: start\n", __FUNCTION__ );
  1167. memset ( &utils, 0, sizeof ( utils ) );
  1168. status = mlx_utils_init ( &utils, pci );
  1169. MLX_CHECK_STATUS ( pci, status, utils_init_err, "mlx_utils_init failed" );
  1170. status = mlx_pci_gw_init ( &utils );
  1171. MLX_CHECK_STATUS ( pci, status, pci_gw_init_err, "mlx_pci_gw_init failed" );
  1172. status = mlx_pci_gw_read ( &utils, PCI_GW_SPACE_NODNIC,
  1173. NODNIC_NIC_INTERFACE_SUPPORTED_OFFSET, &buffer );
  1174. if ( status == MLX_SUCCESS ) {
  1175. buffer >>= NODNIC_NIC_INTERFACE_SUPPORTED_BIT;
  1176. is_supported = ( buffer & 0x1 );
  1177. }
  1178. mlx_pci_gw_teardown( &utils );
  1179. pci_gw_init_err:
  1180. mlx_utils_teardown(&utils);
  1181. utils_init_err:
  1182. DBG ( "%s: NODNIC is %s supported (status = %d)\n",
  1183. __FUNCTION__, ( is_supported ? "": "not" ), status );
  1184. return is_supported;
  1185. }
  1186. void flexboot_nodnic_copy_mac ( uint8_t mac_addr[], uint32_t low_byte,
  1187. uint16_t high_byte ) {
  1188. union mac_addr {
  1189. struct {
  1190. uint32_t low_byte;
  1191. uint16_t high_byte;
  1192. };
  1193. uint8_t mac_addr[ETH_ALEN];
  1194. } mac_addr_aux;
  1195. mac_addr_aux.high_byte = high_byte;
  1196. mac_addr_aux.low_byte = low_byte;
  1197. mac_addr[0] = mac_addr_aux.mac_addr[5];
  1198. mac_addr[1] = mac_addr_aux.mac_addr[4];
  1199. mac_addr[2] = mac_addr_aux.mac_addr[3];
  1200. mac_addr[3] = mac_addr_aux.mac_addr[2];
  1201. mac_addr[4] = mac_addr_aux.mac_addr[1];
  1202. mac_addr[5] = mac_addr_aux.mac_addr[0];
  1203. }
  1204. static mlx_status flexboot_nodnic_get_factory_mac (
  1205. struct flexboot_nodnic *flexboot_nodnic_priv, uint8_t port __unused ) {
  1206. struct mlx_vmac_query_virt_mac virt_mac;
  1207. mlx_status status;
  1208. memset ( & virt_mac, 0, sizeof ( virt_mac ) );
  1209. status = mlx_vmac_query_virt_mac ( flexboot_nodnic_priv->device_priv.utils,
  1210. &virt_mac );
  1211. if ( ! status ) {
  1212. DBGC ( flexboot_nodnic_priv, "NODNIC %p Failed to set the virtual MAC\n"
  1213. ,flexboot_nodnic_priv );
  1214. }
  1215. return status;
  1216. }
  1217. /**
  1218. * Set port masking
  1219. *
  1220. * @v flexboot_nodnic nodnic device
  1221. * @ret rc Return status code
  1222. */
  1223. static int flexboot_nodnic_set_port_masking ( struct flexboot_nodnic *flexboot_nodnic ) {
  1224. unsigned int i;
  1225. nodnic_device_priv *device_priv = &flexboot_nodnic->device_priv;
  1226. flexboot_nodnic->port_mask = 0;
  1227. for ( i = 0; i < device_priv->device_cap.num_ports; i++ ) {
  1228. flexboot_nodnic->port_mask |= (i + 1);
  1229. }
  1230. if ( ! flexboot_nodnic->port_mask ) {
  1231. /* No port was enabled */
  1232. DBGC ( flexboot_nodnic, "NODNIC %p No port was enabled for "
  1233. "booting\n", flexboot_nodnic );
  1234. return -ENETUNREACH;
  1235. }
  1236. return 0;
  1237. }
  1238. int init_mlx_utils ( mlx_utils **utils, struct pci_device *pci ) {
  1239. int rc = 0;
  1240. *utils = ( mlx_utils * ) zalloc ( sizeof ( mlx_utils ) );
  1241. if ( *utils == NULL ) {
  1242. DBGC ( utils, "%s: Failed to allocate utils\n", __FUNCTION__ );
  1243. rc = -1;
  1244. goto err_utils_alloc;
  1245. }
  1246. if ( mlx_utils_init ( *utils, pci ) ) {
  1247. DBGC ( utils, "%s: mlx_utils_init failed\n", __FUNCTION__ );
  1248. rc = -1;
  1249. goto err_utils_init;
  1250. }
  1251. if ( mlx_pci_gw_init ( *utils ) ){
  1252. DBGC ( utils, "%s: mlx_pci_gw_init failed\n", __FUNCTION__ );
  1253. rc = -1;
  1254. goto err_cmd_init;
  1255. }
  1256. return 0;
  1257. mlx_pci_gw_teardown ( *utils );
  1258. err_cmd_init:
  1259. mlx_utils_teardown ( *utils );
  1260. err_utils_init:
  1261. free ( *utils );
  1262. err_utils_alloc:
  1263. *utils = NULL;
  1264. return rc;
  1265. }
  1266. void free_mlx_utils ( mlx_utils **utils ) {
  1267. mlx_pci_gw_teardown ( *utils );
  1268. mlx_utils_teardown ( *utils );
  1269. free ( *utils );
  1270. *utils = NULL;
  1271. }
  1272. /**
  1273. * Initialise Nodnic PCI parameters
  1274. *
  1275. * @v hermon Nodnic device
  1276. */
  1277. static int flexboot_nodnic_alloc_uar ( struct flexboot_nodnic *flexboot_nodnic ) {
  1278. mlx_status status = MLX_SUCCESS;
  1279. struct pci_device *pci = flexboot_nodnic->pci;
  1280. nodnic_uar *uar = &flexboot_nodnic->port[0].port_priv.device->uar;
  1281. if ( ! flexboot_nodnic->device_priv.utils ) {
  1282. uar->virt = NULL;
  1283. DBGC ( flexboot_nodnic, "%s: mlx_utils is not initialized \n", __FUNCTION__ );
  1284. return -EINVAL;
  1285. }
  1286. if ( ! flexboot_nodnic->device_priv.device_cap.support_uar_tx_db ) {
  1287. DBGC ( flexboot_nodnic, "%s: tx db using uar is not supported \n", __FUNCTION__ );
  1288. return -ENOTSUP;
  1289. }
  1290. /* read uar offset then allocate */
  1291. if ( ( status = nodnic_port_set_send_uar_offset ( &flexboot_nodnic->port[0].port_priv ) ) ) {
  1292. DBGC ( flexboot_nodnic, "%s: nodnic_port_set_send_uar_offset failed,"
  1293. "status = %d\n", __FUNCTION__, status );
  1294. return -EINVAL;
  1295. }
  1296. uar->phys = ( pci_bar_start ( pci, FLEXBOOT_NODNIC_HCA_BAR ) + (mlx_uint32)uar->offset );
  1297. uar->virt = ( void * )( ioremap ( uar->phys, FLEXBOOT_NODNIC_PAGE_SIZE ) );
  1298. return status;
  1299. }
  1300. int flexboot_nodnic_probe ( struct pci_device *pci,
  1301. struct flexboot_nodnic_callbacks *callbacks,
  1302. void *drv_priv __unused ) {
  1303. mlx_status status = MLX_SUCCESS;
  1304. struct flexboot_nodnic *flexboot_nodnic_priv = NULL;
  1305. nodnic_device_priv *device_priv = NULL;
  1306. int i = 0;
  1307. if ( ( pci == NULL ) || ( callbacks == NULL ) ) {
  1308. DBGC ( flexboot_nodnic_priv, "%s: Bad Parameter\n", __FUNCTION__ );
  1309. return -EINVAL;
  1310. }
  1311. flexboot_nodnic_priv = zalloc( sizeof ( *flexboot_nodnic_priv ) );
  1312. if ( flexboot_nodnic_priv == NULL ) {
  1313. DBGC ( flexboot_nodnic_priv, "%s: Failed to allocate priv data\n", __FUNCTION__ );
  1314. status = MLX_OUT_OF_RESOURCES;
  1315. goto device_err_alloc;
  1316. }
  1317. /* Register settings
  1318. * Note that pci->priv will be the device private data */
  1319. flexboot_nodnic_priv->pci = pci;
  1320. flexboot_nodnic_priv->callbacks = callbacks;
  1321. pci_set_drvdata ( pci, flexboot_nodnic_priv );
  1322. device_priv = &flexboot_nodnic_priv->device_priv;
  1323. /* init mlx utils */
  1324. status = init_mlx_utils ( & device_priv->utils, pci );
  1325. MLX_FATAL_CHECK_STATUS(status, err_utils_init,
  1326. "init_mlx_utils failed");
  1327. /* init device */
  1328. status = nodnic_device_init( device_priv );
  1329. MLX_FATAL_CHECK_STATUS(status, device_init_err,
  1330. "nodnic_device_init failed");
  1331. status = nodnic_device_get_cap( device_priv );
  1332. MLX_FATAL_CHECK_STATUS(status, get_cap_err,
  1333. "nodnic_device_get_cap failed");
  1334. status = flexboot_nodnic_set_port_masking ( flexboot_nodnic_priv );
  1335. MLX_FATAL_CHECK_STATUS(status, err_set_masking,
  1336. "flexboot_nodnic_set_port_masking failed");
  1337. status = flexboot_nodnic_allocate_infiniband_devices( flexboot_nodnic_priv );
  1338. MLX_FATAL_CHECK_STATUS(status, err_alloc_ibdev,
  1339. "flexboot_nodnic_allocate_infiniband_devices failed");
  1340. /* port init */
  1341. status = flexboot_nodnic_thin_init_ports( flexboot_nodnic_priv );
  1342. MLX_FATAL_CHECK_STATUS(status, err_thin_init_ports,
  1343. "flexboot_nodnic_thin_init_ports failed");
  1344. if ( ( status = flexboot_nodnic_alloc_uar ( flexboot_nodnic_priv ) ) ) {
  1345. DBGC(flexboot_nodnic_priv, "%s: flexboot_nodnic_pci_init failed"
  1346. " ( status = %d )\n",__FUNCTION__, status );
  1347. }
  1348. /* device reg */
  1349. status = flexboot_nodnic_set_ports_type( flexboot_nodnic_priv );
  1350. MLX_CHECK_STATUS( flexboot_nodnic_priv, status, err_set_ports_types,
  1351. "flexboot_nodnic_set_ports_type failed");
  1352. status = flexboot_nodnic_ports_register_dev( flexboot_nodnic_priv );
  1353. MLX_FATAL_CHECK_STATUS(status, reg_err,
  1354. "flexboot_nodnic_ports_register_dev failed");
  1355. for ( i = 0; i < device_priv->device_cap.num_ports; i++ ) {
  1356. if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) )
  1357. continue;
  1358. flexboot_nodnic_get_factory_mac ( flexboot_nodnic_priv, i );
  1359. }
  1360. /* Update ETH operations with IRQ function if supported */
  1361. DBGC ( flexboot_nodnic_priv, "%s: %s IRQ function\n",
  1362. __FUNCTION__, ( callbacks->irq ? "Valid" : "No" ) );
  1363. flexboot_nodnic_eth_operations.irq = callbacks->irq;
  1364. return 0;
  1365. flexboot_nodnic_ports_unregister_dev ( flexboot_nodnic_priv );
  1366. reg_err:
  1367. err_set_ports_types:
  1368. err_thin_init_ports:
  1369. err_alloc_ibdev:
  1370. err_set_masking:
  1371. get_cap_err:
  1372. nodnic_device_teardown ( device_priv );
  1373. device_init_err:
  1374. free_mlx_utils ( & device_priv->utils );
  1375. err_utils_init:
  1376. free ( flexboot_nodnic_priv );
  1377. device_err_alloc:
  1378. return status;
  1379. }
  1380. void flexboot_nodnic_remove ( struct pci_device *pci )
  1381. {
  1382. struct flexboot_nodnic *flexboot_nodnic_priv = pci_get_drvdata ( pci );
  1383. nodnic_device_priv *device_priv = & ( flexboot_nodnic_priv->device_priv );
  1384. flexboot_nodnic_ports_unregister_dev ( flexboot_nodnic_priv );
  1385. nodnic_device_teardown( device_priv );
  1386. free_mlx_utils ( & device_priv->utils );
  1387. free( flexboot_nodnic_priv );
  1388. }