37 err(
"SRAM destination target to available on FlexCopII(b)\n");
40 deb_sram(
"sram dest: %x target: %x\n", dest, target);
80 for (i = 0; i < len; i++) {
81 command = bank | addr | 0x04000000 | (*buf << 0x10);
85 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
91 printk(
"%s: SRAM timeout\n", __func__);
93 write_reg_dw(adapter, 0x700, command);
100 static void flex_sram_read(
struct adapter *adapter,
u32 bank,
u32 addr,
u8 *buf,
u32 len)
105 for (i = 0; i < len; i++) {
106 command = bank | addr | 0x04008000;
110 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
116 printk(
"%s: SRAM timeout\n", __func__);
118 write_reg_dw(adapter, 0x700, command);
122 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
128 printk(
"%s: SRAM timeout\n", __func__);
130 value = read_reg_dw(adapter, 0x700) >> 0x10;
132 *buf = (value & 0xff);
139 static void sram_write_chunk(
struct adapter *adapter,
u32 addr,
u8 *buf,
u16 len)
145 if (adapter->dw_sram_type == 0x20000) {
146 bank = (addr & 0x18000) << 0x0d;
149 if (adapter->dw_sram_type == 0x00000) {
150 if ((addr >> 0x0f) == 0)
155 flex_sram_write(adapter, bank, addr & 0x7fff, buf, len);
158 static void sram_read_chunk(
struct adapter *adapter,
u32 addr,
u8 *buf,
u16 len)
163 if (adapter->dw_sram_type == 0x20000) {
164 bank = (addr & 0x18000) << 0x0d;
167 if (adapter->dw_sram_type == 0x00000) {
168 if ((addr >> 0x0f) == 0)
173 flex_sram_read(adapter, bank, addr & 0x7fff, buf, len);
176 static void sram_read(
struct adapter *adapter,
u32 addr,
u8 *buf,
u32 len)
184 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
185 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
188 sram_read_chunk(adapter, addr, buf, length);
195 static void sram_write(
struct adapter *adapter,
u32 addr,
u8 *buf,
u32 len)
204 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
205 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
208 sram_write_chunk(adapter, addr, buf, length);
215 static void sram_set_size(
struct adapter *adapter,
u32 mask)
217 write_reg_dw(adapter, 0x71c,
218 (mask | (~0x30000 & read_reg_dw(adapter, 0x71c))));
221 static void sram_init(
struct adapter *adapter)
224 tmp = read_reg_dw(adapter, 0x71c);
225 write_reg_dw(adapter, 0x71c, 1);
227 if (read_reg_dw(adapter, 0x71c) != 0) {
228 write_reg_dw(adapter, 0x71c, tmp);
229 adapter->dw_sram_type = tmp & 0x30000;
230 ddprintk(
"%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
232 adapter->dw_sram_type = 0x10000;
233 ddprintk(
"%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
237 static int sram_test_location(
struct adapter *adapter,
u32 mask,
u32 addr)
240 dprintk(
"%s: mask = %x, addr = %x\n", __func__, mask, addr);
242 sram_set_size(adapter, mask);
248 sram_write(adapter, addr, &tmp2, 1);
249 sram_write(adapter, addr + 4, &tmp1, 1);
254 sram_read(adapter, addr, &tmp2, 1);
255 sram_read(adapter, addr, &tmp2, 1);
257 dprintk(
"%s: wrote 0xa5, read 0x%2x\n", __func__, tmp2);
265 sram_write(adapter, addr, &tmp2, 1);
266 sram_write(adapter, addr + 4, &tmp1, 1);
271 sram_read(adapter, addr, &tmp2, 1);
272 sram_read(adapter, addr, &tmp2, 1);
274 dprintk(
"%s: wrote 0x5a, read 0x%2x\n", __func__, tmp2);
281 static u32 sram_length(
struct adapter *adapter)
283 if (adapter->dw_sram_type == 0x10000)
285 if (adapter->dw_sram_type == 0x00000)
287 if (adapter->dw_sram_type == 0x20000)
312 write_reg_dw(adapter, 0x71c, 1);
313 tmp3 = read_reg_dw(adapter, 0x71c);
314 dprintk(
"%s: tmp3 = %x\n", __func__, tmp3);
315 write_reg_dw(adapter, 0x71c, tmp2);
320 sram_set_size(adapter, 0x10000);
322 write_reg_dw(adapter, 0x208, tmp);
323 dprintk(
"%s: sram size = 32K\n", __func__);
327 if (sram_test_location(adapter, 0x20000, 0x18000) != 0) {
328 sram_set_size(adapter, 0x20000);
330 write_reg_dw(adapter, 0x208, tmp);
331 dprintk(
"%s: sram size = 128K\n", __func__);
335 if (sram_test_location(adapter, 0x00000, 0x10000) != 0) {
336 sram_set_size(adapter, 0x00000);
338 write_reg_dw(adapter, 0x208, tmp);
339 dprintk(
"%s: sram size = 64K\n", __func__);
343 if (sram_test_location(adapter, 0x10000, 0x00000) != 0) {
344 sram_set_size(adapter, 0x10000);
346 write_reg_dw(adapter, 0x208, tmp);
347 dprintk(
"%s: sram size = 32K\n", __func__);
351 sram_set_size(adapter, 0x10000);
353 write_reg_dw(adapter, 0x208, tmp);
354 dprintk(
"%s: SRAM detection failed. Set to 32K \n", __func__);
358 static void sll_detect_sram_size(
struct adapter *adapter)
360 sram_detect_for_flex2(adapter);