2 * carl9170 firmware - used by the ar9170 wireless device
6 * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7 * Copyright (c) 2007-2009 Atheros Communications, Inc.
8 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
9 * Copyright 2009-2011 Christian Lamparter <chunkeey@googlemail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; If not, see <http://www.gnu.org/licenses/>.
28 #ifdef CONFIG_CARL9170FW_SECURITY_ENGINE
29 static void disable_cam_user(const uint16_t userId)
32 andl(AR9170_MAC_REG_CAM_ROLL_CALL_TBL_L, (~((uint32_t) 1 << userId)));
33 else if (userId <= 63)
34 andl(AR9170_MAC_REG_CAM_ROLL_CALL_TBL_H, (~((uint32_t) 1 << (userId - 32))));
37 static void enable_cam_user(const uint16_t userId)
40 orl(AR9170_MAC_REG_CAM_ROLL_CALL_TBL_L, (((uint32_t) 1) << userId));
41 else if (userId <= 63)
42 orl(AR9170_MAC_REG_CAM_ROLL_CALL_TBL_H, (((uint32_t) 1) << (userId - 32)));
45 static void wait_for_cam_read_ready(void)
47 while ((get(AR9170_MAC_REG_CAM_STATE) & AR9170_MAC_CAM_STATE_READ_PENDING) == 0) {
54 static void wait_for_cam_write_ready(void)
56 while ((get(AR9170_MAC_REG_CAM_STATE) & AR9170_MAC_CAM_STATE_WRITE_PENDING) == 0) {
63 static void HW_CAM_Avail(void)
68 tmpValue = get(AR9170_MAC_REG_CAM_MODE);
69 } while (tmpValue & AR9170_MAC_CAM_HOST_PENDING);
72 static void HW_CAM_Write128(const uint32_t address, const uint32_t *data)
76 set(AR9170_MAC_REG_CAM_DATA0, data[0]);
77 set(AR9170_MAC_REG_CAM_DATA1, data[1]);
78 set(AR9170_MAC_REG_CAM_DATA2, data[2]);
79 set(AR9170_MAC_REG_CAM_DATA3, data[3]);
81 set(AR9170_MAC_REG_CAM_ADDR, address | AR9170_MAC_CAM_ADDR_WRITE);
83 wait_for_cam_write_ready();
86 static void HW_CAM_Read128(const uint32_t address, uint32_t *data)
90 set(AR9170_MAC_REG_CAM_ADDR, address);
92 wait_for_cam_read_ready();
94 data[0] = get(AR9170_MAC_REG_CAM_DATA0);
95 data[1] = get(AR9170_MAC_REG_CAM_DATA1);
96 data[2] = get(AR9170_MAC_REG_CAM_DATA2);
97 data[3] = get(AR9170_MAC_REG_CAM_DATA3);
100 void set_key(const struct carl9170_set_key_cmd *key)
103 uint16_t row, wordId, nibbleId, i;
105 if (key->user > (AR9170_CAM_MAX_USER + 3))
112 disable_cam_user(key->user);
114 /* Set encrypt type */
115 if (key->user >= AR9170_CAM_MAX_USER) {
117 row = DEFAULT_ENCRY_TYPE;
119 nibbleId = (key->user - AR9170_CAM_MAX_USER) & 0x7;
121 row = ENCRY_TYPE_START_ADDR + (key->user >> 5);
122 wordId = (key->user >> 3) & 0x3;
123 nibbleId = key->user & 0x7;
126 HW_CAM_Read128(row, data);
127 data[wordId] &= (~(0xf << ((uint32_t) nibbleId * 4)));
128 data[wordId] |= (key->type << ((uint32_t) nibbleId * 4));
129 HW_CAM_Write128(row, data);
131 /* Set MAC address */
132 if (key->user < AR9170_CAM_MAX_USER) {
134 wordId = (key->user >> 2) & 0x3;
135 byteId = key->user & 0x3;
136 row = (key->user >> 4) * 6;
138 for (i = 0; i < 6; i++) {
139 HW_CAM_Read128(row + i, data);
140 data[wordId] &= (~(0xff << ((uint32_t) byteId * 8)));
141 data[wordId] |= (key->macAddr[i] << ((uint32_t) byteId * 8));
142 HW_CAM_Write128(row + i, data);
147 row = KEY_START_ADDR + (key->user * 2) + key->keyId;
149 HW_CAM_Write128(row, key->key);
152 enable_cam_user(key->user);
155 void disable_key(const struct carl9170_disable_key_cmd *key)
157 disable_cam_user(key->user);
160 #endif /* CONFIG_CARL9170FW_SECURITY_ENGINE */