* Allocate and Initialize an ULP session and set it's state to INITIALIZED. * If it's already initialized simply return the already existing session. */
| 1360 | * If it's already initialized simply return the already existing session. |
| 1361 | */ |
| 1362 | static struct bnxt_ulp_session_state * |
| 1363 | ulp_session_init(struct bnxt *bp, |
| 1364 | bool *init) |
| 1365 | { |
| 1366 | struct rte_pci_device *pci_dev; |
| 1367 | struct rte_pci_addr *pci_addr; |
| 1368 | struct bnxt_ulp_session_state *session; |
| 1369 | int rc = 0; |
| 1370 | |
| 1371 | if (!bp) |
| 1372 | return NULL; |
| 1373 | |
| 1374 | pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device); |
| 1375 | pci_addr = &pci_dev->addr; |
| 1376 | |
| 1377 | pthread_mutex_lock(&bnxt_ulp_global_mutex); |
| 1378 | |
| 1379 | session = ulp_get_session(bp, pci_addr); |
| 1380 | if (!session) { |
| 1381 | /* Not Found the session Allocate a new one */ |
| 1382 | session = rte_zmalloc("bnxt_ulp_session", |
| 1383 | sizeof(struct bnxt_ulp_session_state), |
| 1384 | 0); |
| 1385 | if (!session) { |
| 1386 | BNXT_TF_DBG(ERR, |
| 1387 | "Allocation failed for bnxt_ulp_session\n"); |
| 1388 | pthread_mutex_unlock(&bnxt_ulp_global_mutex); |
| 1389 | return NULL; |
| 1390 | |
| 1391 | } else { |
| 1392 | /* Add it to the queue */ |
| 1393 | session->pci_info.domain = pci_addr->domain; |
| 1394 | session->pci_info.bus = pci_addr->bus; |
| 1395 | memcpy(session->dsn, bp->dsn, sizeof(session->dsn)); |
| 1396 | rc = pthread_mutex_init(&session->bnxt_ulp_mutex, NULL); |
| 1397 | if (rc) { |
| 1398 | BNXT_TF_DBG(ERR, "mutex create failed\n"); |
| 1399 | pthread_mutex_unlock(&bnxt_ulp_global_mutex); |
| 1400 | return NULL; |
| 1401 | } |
| 1402 | STAILQ_INSERT_TAIL(&bnxt_ulp_session_list, |
| 1403 | session, next); |
| 1404 | } |
| 1405 | } |
| 1406 | ulp_context_initialized(session, init); |
| 1407 | pthread_mutex_unlock(&bnxt_ulp_global_mutex); |
| 1408 | return session; |
| 1409 | } |
| 1410 | |
| 1411 | /* |
| 1412 | * When a device is closed, remove it's associated session from the global |
no test coverage detected