Files
@ 89a4bb14d085
Branch filter:
Location: vmkdrivers/vmkdrivers/src_9/drivers/net/bnx2/cnic_register.c - annotation
89a4bb14d085
6.6 KiB
text/x-csrc
ESXi-5.5-U1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | 763922b5834e 763922b5834e 91e0d39c9812 763922b5834e 91e0d39c9812 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e 763922b5834e | /* cnic_register.c: Broadcom CNIC Registration Agent
*
* Copyright (c) 2010-2013 Broadcom Corporation
*
* Portions Copyright (c) VMware, Inc. 2010-2013, All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* Written by:
*/
#include <linux/version.h>
#if (LINUX_VERSION_CODE < 0x020612)
#include <linux/config.h>
#endif
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/mutex.h>
#include "cnic_register.h"
#include "vmkapi.h"
#define DRV_MODULE_NAME "cnic_register"
#define PFX DRV_MODULE_NAME ": "
static char version[] __devinitdata =
"Broadcom NetXtreme II CNIC Registration Agent " DRV_MODULE_NAME " v" CNIC_REGISTER_MODULE_VERSION " (" CNIC_REGISTER_MODULE_RELDATE ")\n";
MODULE_DESCRIPTION("Broadcom NetXtreme II CNIC Registration Agent");
MODULE_LICENSE("GPL");
MODULE_VERSION(CNIC_REGISTER_MODULE_VERSION);
#define MAX_ADAPTER_NAME 128
#define TABLE_SIZE 16
struct cnic_registration {
char name[MAX_ADAPTER_NAME];
vmk_ModuleID modID;
int refcnt_increased;
void *callback;
};
/* static module data */
static struct mutex cnic_register_mutex;
static struct cnic_registration registration_table[TABLE_SIZE];
static int
__init cnic_register_init(void)
{
int rc = 0;
int i;
mutex_init(&cnic_register_mutex);
memset(registration_table, 0, sizeof(registration_table));
for (i = 0; i < TABLE_SIZE; ++i) {
registration_table[i].modID = VMK_INVALID_MODULE_ID;
}
printk(KERN_INFO "%s", version);
return rc;
}
int
cnic_register_adapter(const char * name, void *callback)
{
struct cnic_registration *entry, *new = NULL;
int rc = 0;
int i;
if (name == NULL || name[0] == '\0' || callback == NULL) {
printk(KERN_ERR PFX "cnic_register_adapter called with NULL parameters\n");
return -EINVAL;
}
mutex_lock(&cnic_register_mutex);
/* search table for duplicate entry, first empty slot */
for (i = 0; i < TABLE_SIZE; ++i) {
entry = ®istration_table[i];
if (entry->callback == NULL) {
if (new == NULL)
new = entry;
} else if (strncmp(name, entry->name, MAX_ADAPTER_NAME) == 0) {
rc = -EEXIST;
goto done;
}
}
/* table full ? */
if (new == NULL) {
rc = -E2BIG;
goto done;
}
/* record entry */
new->callback = callback;
new->modID = vmk_ModuleStackTop();
snprintf(new->name, MAX_ADAPTER_NAME, "%s", name);
done:
mutex_unlock(&cnic_register_mutex);
return rc;
}
EXPORT_SYMBOL(cnic_register_adapter);
void *
cnic_register_get_callback(const char * name)
{
struct cnic_registration *entry;
void *ret = NULL;
int i;
if (name == NULL || name[0] == '\0') {
printk(KERN_ERR PFX "cnic_register_get_callback called with NULL parameters\n");
return NULL;
}
mutex_lock(&cnic_register_mutex);
for (i = 0; i < TABLE_SIZE; ++i) {
entry = ®istration_table[i];
if (strncmp(name, entry->name, MAX_ADAPTER_NAME) == 0) {
ret = entry->callback;
if (entry->refcnt_increased == 0) {
BUG_ON(entry->modID == VMK_INVALID_MODULE_ID);
vmk_ModuleIncUseCount(entry->modID);
entry->refcnt_increased = 1;
}
goto done;
}
}
done:
mutex_unlock(&cnic_register_mutex);
return ret;
}
EXPORT_SYMBOL(cnic_register_get_callback);
int
cnic_register_get_table_size(void)
{
return TABLE_SIZE;
}
EXPORT_SYMBOL(cnic_register_get_table_size);
int
cnic_register_get_callback_by_index(int index, char * name, void **callback)
{
struct cnic_registration *entry;
int rc = 0;
if (index < 0 || index >= TABLE_SIZE) {
printk(KERN_ERR PFX "cnic_register_get_callback_by_index called with invalid index\n");
return -EINVAL;
}
entry = ®istration_table[index];
mutex_lock(&cnic_register_mutex);
if (entry->name[0] != '\0') {
snprintf(name, MAX_ADAPTER_NAME, "%s", entry->name);
if (entry->refcnt_increased == 0) {
BUG_ON(entry->modID == VMK_INVALID_MODULE_ID);
vmk_ModuleIncUseCount(entry->modID);
entry->refcnt_increased = 1;
}
*callback = entry->callback;
} else {
rc = -ENOENT;
}
mutex_unlock(&cnic_register_mutex);
return rc;
}
EXPORT_SYMBOL(cnic_register_get_callback_by_index);
void
cnic_register_cancel(const char * name)
{
struct cnic_registration *entry;
int i;
if (name == NULL || name[0] == '\0') {
printk(KERN_ERR PFX "cnic_register_cancel called with NULL parameters\n");
return;
}
mutex_lock(&cnic_register_mutex);
for (i = 0; i < TABLE_SIZE; ++i) {
entry = ®istration_table[i];
if (strncmp(name, entry->name, MAX_ADAPTER_NAME) == 0) {
/*
* To safely remove callback info provided by bnx2/bnx2x,
* cnic must have been unloaded, and refcnt on bnx2/bnx2x
* has been released.
*
* The following BUG_ON assertion strictly limits
* registration_table to be lookup'ed by cnic module
* only, which is the current expected situation.
*/
BUG_ON(entry->refcnt_increased != 0);
entry->callback = NULL;
entry->name[0] = '\0';
entry->modID = VMK_INVALID_MODULE_ID;
}
}
mutex_unlock(&cnic_register_mutex);
}
EXPORT_SYMBOL(cnic_register_cancel);
void
cnic_register_release_all_callbacks()
{
struct cnic_registration *entry;
int i;
mutex_lock(&cnic_register_mutex);
for (i = 0; i < TABLE_SIZE; ++i) {
entry = ®istration_table[i];
if (entry->callback) {
BUG_ON(entry->refcnt_increased != 1);
vmk_ModuleDecUseCount(entry->modID);
entry->refcnt_increased = 0;
}
}
mutex_unlock(&cnic_register_mutex);
}
EXPORT_SYMBOL(cnic_register_release_all_callbacks);
module_init(cnic_register_init);
|