Skip to content

Commit

Permalink
Merge pull request #96 from ibm-genwqe/fix_for_multicard
Browse files Browse the repository at this point in the history
Fix for multicard
  • Loading branch information
fhaverkamp committed Mar 22, 2016
2 parents b732d39 + 631a402 commit 2a57c4d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
4 changes: 3 additions & 1 deletion include/libddcb.h
Expand Up @@ -54,10 +54,12 @@ extern "C" {
#define DDCB_MODE_ASYNC 0x0008 /* ... */
#define DDCB_MODE_NONBLOCK 0x0010 /* non blocking, -EBUSY */
#define DDCB_MODE_POLLING 0x0020 /* polling */
#define DDCB_MODE_MASTER 0x08000000 /* Open Master Context, Slave is default, CAPI ony */
#define DDCB_MODE_MASTER 0x08000000
/* Open Master Context, Slave is default, CAPI ony */

#define DDCB_APPL_ID_IGNORE 0x0000000000000000 /* Ignore applid */
#define DDCB_APPL_ID_MASK 0x00000000ffffffff /* Valid bits */
#define DDCB_APPL_ID_MASK_VER 0x000000ffffffffff /* Valid bits */

#define DDCB_OK 0
#define DDCB_ERRNO -401 /* libc call went wrong */
Expand Down
2 changes: 1 addition & 1 deletion include/libzHW.h
@@ -1,5 +1,5 @@
/*
* Copyright 2014,2015 International Business Machines
* Copyright 2014, 2016 International Business Machines
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
28 changes: 18 additions & 10 deletions lib/ddcb_capi.c
@@ -1,5 +1,5 @@
/*
* Copyright 2015, International Business Machines
* Copyright 2015, 2016, International Business Machines
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,6 +106,7 @@ struct ttxs {
int card_next; /* Next card to try in redundant mode */
unsigned int mode;
uint64_t app_id; /* a copy of MMIO_APP_VERSION_REG */
uint64_t app_id_mask; /* used when opening the handle */
struct ttxs *verify;
};

Expand Down Expand Up @@ -157,7 +158,7 @@ struct dev_ctx {
struct dev_ctx *verify; /* Verify field */
};

#define NUM_CARDS 2 /* max number of CAPI cards in system */
#define NUM_CARDS 4 /* max number of CAPI cards in system */

static ddcb_t my_ddcbs[NUM_CARDS][NUM_DDCBS] __attribute__((aligned(64*1024)));
static struct dev_ctx my_ctx[NUM_CARDS];
Expand Down Expand Up @@ -725,6 +726,8 @@ static void *card_open(int card_no, unsigned int mode, int *card_rc,
/* Inc use count and initialize AFU on first open */
sem_init(&ttx->wait_sem, 0, 0);
ttx->card_no = card_no; /* Save only right now */
ttx->app_id = appl_id;
ttx->app_id_mask = appl_id_mask;
ttx->card_next = rand() % NUM_CARDS; /* start always random */
ttx->mode = mode;
ttx->verify = ttx;
Expand Down Expand Up @@ -1288,17 +1291,22 @@ static int card_write_reg32(void *card_data, uint32_t offs, uint32_t data)
return DDCB_ERR_INVAL;
}

/**
* The CAPI card implementation is always matching the zEDCv2
* compressor implementation. It is complicated to return the right
* version in case of multicard mode, since the DDCB execution is
* altering through the cards. The right solution here is to enhance
* the appl_id_mask, such that the version bits are considered and
* only cards with the same id are being used.
*/
static uint64_t _card_get_app_id(void *card_data)
{
struct ttxs *ttx = (struct ttxs*)card_data;
struct dev_ctx *ctx;
struct ttxs *ttx = (struct ttxs *)card_data;

if (ttx && (ttx->verify == ttx)) {
ctx = ttx->ctx;
if (ctx)
return ctx->app_id;
}
return 0;
if (ttx == NULL)
return DDCB_ERR_INVAL;

return ttx->app_id;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion lib/libzHW.c
Expand Up @@ -426,6 +426,8 @@ zedc_handle_t zedc_open(int dev_no, int dev_type, int mode, int *err_code)
{
char *env;
zedc_handle_t zedc;
uint64_t app_id = DDCB_APPL_ID_GZIP;
uint64_t app_id_mask = DDCB_APPL_ID_MASK;

zedc = malloc(sizeof(*zedc));
if (!zedc) {
Expand All @@ -435,9 +437,15 @@ zedc_handle_t zedc_open(int dev_no, int dev_type, int mode, int *err_code)
memset(zedc, 0, sizeof(*zedc));
zedc->mode = mode;

/* Check Appl id GZIP Version 2 */
if (dev_no == ACCEL_REDUNDANT) {
app_id = DDCB_APPL_ID_GZIP2;
app_id_mask = DDCB_APPL_ID_MASK_VER;
}

/* Check Appl id GZIP Version 2 */
zedc->card = accel_open(dev_no, dev_type, mode, &zedc->card_rc,
DDCB_APPL_ID_GZIP, DDCB_APPL_ID_MASK);
app_id, app_id_mask);
if (zedc->card == NULL) {
*err_code = ZEDC_ERR_CARD;
goto free_zedc;
Expand Down

0 comments on commit 2a57c4d

Please sign in to comment.