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, 2010 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, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #ifdef CONFIG_CARL9170FW_SECURITY_ENGINE
30 static void disable_cam_user(const uint16_t userId)
33 andl(AR9170_MAC_REG_CAM_ROLL_CALL_TBL_L, (~((uint32_t) 1 << userId)));
34 else if (userId <= 63)
35 andl(AR9170_MAC_REG_CAM_ROLL_CALL_TBL_H, (~((uint32_t) 1 << (userId - 32))));
38 static void enable_cam_user(const uint16_t userId)
41 orl(AR9170_MAC_REG_CAM_ROLL_CALL_TBL_L, (((uint32_t) 1) << userId));
42 else if (userId <= 63)
43 orl(AR9170_MAC_REG_CAM_ROLL_CALL_TBL_H, (((uint32_t) 1) << (userId - 32)));
46 static void wait_for_cam_read_ready(void)
48 while ((get(AR9170_MAC_REG_CAM_STATE) & AR9170_MAC_CAM_STATE_READ_PENDING) == 0) {
55 static void wait_for_cam_write_ready(void)
57 while ((get(AR9170_MAC_REG_CAM_STATE) & AR9170_MAC_CAM_STATE_WRITE_PENDING) == 0) {
64 static void HW_CAM_Avail(void)
69 tmpValue = get(AR9170_MAC_REG_CAM_MODE);
70 } while (tmpValue & AR9170_MAC_CAM_HOST_PENDING);
73 static void HW_CAM_Write128(const uint32_t address, const uint32_t *data)
77 set(AR9170_MAC_REG_CAM_DATA0, data[0]);
78 set(AR9170_MAC_REG_CAM_DATA1, data[1]);
79 set(AR9170_MAC_REG_CAM_DATA2, data[2]);
80 set(AR9170_MAC_REG_CAM_DATA3, data[3]);
82 set(AR9170_MAC_REG_CAM_ADDR, address | AR9170_MAC_CAM_ADDR_WRITE);
84 wait_for_cam_write_ready();
87 static void HW_CAM_Read128(const uint32_t address, uint32_t *data)
91 set(AR9170_MAC_REG_CAM_ADDR, address);
93 wait_for_cam_read_ready();
95 data[0] = get(AR9170_MAC_REG_CAM_DATA0);
96 data[1] = get(AR9170_MAC_REG_CAM_DATA1);
97 data[2] = get(AR9170_MAC_REG_CAM_DATA2);
98 data[3] = get(AR9170_MAC_REG_CAM_DATA3);
101 void set_key(const struct carl9170_set_key_cmd *key)
104 uint16_t row, wordId, nibbleId, i;
106 if (key->user > (AR9170_CAM_MAX_USER + 3))
113 disable_cam_user(key->user);
115 /* Set encrypt type */
116 if (key->user >= AR9170_CAM_MAX_USER) {
118 row = DEFAULT_ENCRY_TYPE;
120 nibbleId = (key->user - AR9170_CAM_MAX_USER) & 0x7;
122 row = ENCRY_TYPE_START_ADDR + (key->user >> 5);
123 wordId = (key->user >> 3) & 0x3;
124 nibbleId = key->user & 0x7;
127 HW_CAM_Read128(row, data);
128 data[wordId] &= (~(0xf << ((uint32_t) nibbleId * 4)));
129 data[wordId] |= (key->type << ((uint32_t) nibbleId * 4));
130 HW_CAM_Write128(row, data);
132 /* Set MAC address */
133 if (key->user < AR9170_CAM_MAX_USER) {
135 wordId = (key->user >> 2) & 0x3;
136 byteId = key->user & 0x3;
137 row = (key->user >> 4) * 6;
139 for (i = 0; i < 6; i++) {
140 HW_CAM_Read128(row + i, data);
141 data[wordId] &= (~(0xff << ((uint32_t) byteId * 8)));
142 data[wordId] |= (key->macAddr[i] << ((uint32_t) byteId * 8));
143 HW_CAM_Write128(row + i, data);
148 row = KEY_START_ADDR + (key->user * 2) + key->keyId;
150 HW_CAM_Write128(row, key->key);
153 enable_cam_user(key->user);
156 void disable_key(const struct carl9170_disable_key_cmd *key)
158 disable_cam_user(key->user);
161 #endif /* CONFIG_CARL9170FW_SECURITY_ENGINE */