~ubuntu-branches/ubuntu/karmic/linux-mvl-dove/karmic-proposed

« back to all changes in this revision

Viewing changes to drivers/net/wireless/iwlwifi/iwl-eeprom.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader
  • Date: 2010-03-10 22:24:12 UTC
  • mto: (15.1.2 karmic-security)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20100310222412-k86m3r53jw0je7x1
Tags: upstream-2.6.31
ImportĀ upstreamĀ versionĀ 2.6.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
152
152
}
153
153
EXPORT_SYMBOL(iwlcore_eeprom_verify_signature);
154
154
 
155
 
static void iwl_set_otp_access(struct iwl_priv *priv, enum iwl_access_mode mode)
156
 
{
157
 
        u32 otpgp;
158
 
 
159
 
        otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
160
 
        if (mode == IWL_OTP_ACCESS_ABSOLUTE)
161
 
                iwl_clear_bit(priv, CSR_OTP_GP_REG,
162
 
                                CSR_OTP_GP_REG_OTP_ACCESS_MODE);
163
 
        else
164
 
                iwl_set_bit(priv, CSR_OTP_GP_REG,
165
 
                                CSR_OTP_GP_REG_OTP_ACCESS_MODE);
166
 
}
167
 
 
168
155
static int iwlcore_get_nvm_type(struct iwl_priv *priv)
169
156
{
170
157
        u32 otpgp;
262
249
        return ret;
263
250
}
264
251
 
265
 
static int iwl_read_otp_word(struct iwl_priv *priv, u16 addr, u16 *eeprom_data)
266
 
{
267
 
        int ret = 0;
268
 
        u32 r;
269
 
        u32 otpgp;
270
 
 
271
 
        _iwl_write32(priv, CSR_EEPROM_REG,
272
 
                     CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
273
 
        ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
274
 
                                  CSR_EEPROM_REG_READ_VALID_MSK,
275
 
                                  IWL_EEPROM_ACCESS_TIMEOUT);
276
 
        if (ret < 0) {
277
 
                IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
278
 
                return ret;
279
 
        }
280
 
        r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
281
 
        /* check for ECC errors: */
282
 
        otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
283
 
        if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
284
 
                /* stop in this case */
285
 
                /* set the uncorrectable OTP ECC bit for acknowledgement */
286
 
                iwl_set_bit(priv, CSR_OTP_GP_REG,
287
 
                        CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
288
 
                IWL_ERR(priv, "Uncorrectable OTP ECC error, abort OTP read\n");
289
 
                return -EINVAL;
290
 
        }
291
 
        if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
292
 
                /* continue in this case */
293
 
                /* set the correctable OTP ECC bit for acknowledgement */
294
 
                iwl_set_bit(priv, CSR_OTP_GP_REG,
295
 
                                CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
296
 
                IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
297
 
        }
298
 
        *eeprom_data = le16_to_cpu((__force __le16)(r >> 16));
299
 
        return 0;
300
 
}
301
 
 
302
 
/*
303
 
 * iwl_is_otp_empty: check for empty OTP
304
 
 */
305
 
static bool iwl_is_otp_empty(struct iwl_priv *priv)
306
 
{
307
 
        u16 next_link_addr = 0, link_value;
308
 
        bool is_empty = false;
309
 
 
310
 
        /* locate the beginning of OTP link list */
311
 
        if (!iwl_read_otp_word(priv, next_link_addr, &link_value)) {
312
 
                if (!link_value) {
313
 
                        IWL_ERR(priv, "OTP is empty\n");
314
 
                        is_empty = true;
315
 
                }
316
 
        } else {
317
 
                IWL_ERR(priv, "Unable to read first block of OTP list.\n");
318
 
                is_empty = true;
319
 
        }
320
 
 
321
 
        return is_empty;
322
 
}
323
 
 
324
 
 
325
 
/*
326
 
 * iwl_find_otp_image: find EEPROM image in OTP
327
 
 *   finding the OTP block that contains the EEPROM image.
328
 
 *   the last valid block on the link list (the block _before_ the last block)
329
 
 *   is the block we should read and used to configure the device.
330
 
 *   If all the available OTP blocks are full, the last block will be the block
331
 
 *   we should read and used to configure the device.
332
 
 *   only perform this operation if shadow RAM is disabled
333
 
 */
334
 
static int iwl_find_otp_image(struct iwl_priv *priv,
335
 
                                        u16 *validblockaddr)
336
 
{
337
 
        u16 next_link_addr = 0, link_value = 0, valid_addr;
338
 
        int usedblocks = 0;
339
 
 
340
 
        /* set addressing mode to absolute to traverse the link list */
341
 
        iwl_set_otp_access(priv, IWL_OTP_ACCESS_ABSOLUTE);
342
 
 
343
 
        /* checking for empty OTP or error */
344
 
        if (iwl_is_otp_empty(priv))
345
 
                return -EINVAL;
346
 
 
347
 
        /*
348
 
         * start traverse link list
349
 
         * until reach the max number of OTP blocks
350
 
         * different devices have different number of OTP blocks
351
 
         */
352
 
        do {
353
 
                /* save current valid block address
354
 
                 * check for more block on the link list
355
 
                 */
356
 
                valid_addr = next_link_addr;
357
 
                next_link_addr = link_value * sizeof(u16);
358
 
                IWL_DEBUG_INFO(priv, "OTP blocks %d addr 0x%x\n",
359
 
                               usedblocks, next_link_addr);
360
 
                if (iwl_read_otp_word(priv, next_link_addr, &link_value))
361
 
                        return -EINVAL;
362
 
                if (!link_value) {
363
 
                        /*
364
 
                         * reach the end of link list, return success and
365
 
                         * set address point to the starting address
366
 
                         * of the image
367
 
                         */
368
 
                        *validblockaddr = valid_addr;
369
 
                        /* skip first 2 bytes (link list pointer) */
370
 
                        *validblockaddr += 2;
371
 
                        return 0;
372
 
                }
373
 
                /* more in the link list, continue */
374
 
                usedblocks++;
375
 
        } while (usedblocks <= priv->cfg->max_ll_items);
376
 
 
377
 
        /* OTP has no valid blocks */
378
 
        IWL_DEBUG_INFO(priv, "OTP has no valid blocks\n");
379
 
        return -EINVAL;
380
 
}
381
 
 
382
252
/**
383
253
 * iwl_eeprom_init - read EEPROM contents
384
254
 *
393
263
        int sz;
394
264
        int ret;
395
265
        u16 addr;
396
 
        u16 validblockaddr = 0;
397
 
        u16 cache_addr = 0;
 
266
        u32 otpgp;
398
267
 
399
268
        priv->nvm_device_type = iwlcore_get_nvm_type(priv);
400
269
 
401
270
        /* allocate eeprom */
402
 
        IWL_DEBUG_INFO(priv, "NVM size = %d\n", priv->cfg->eeprom_size);
 
271
        if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
 
272
                priv->cfg->eeprom_size =
 
273
                        OTP_BLOCK_SIZE * OTP_LOWER_BLOCKS_TOTAL;
403
274
        sz = priv->cfg->eeprom_size;
404
275
        priv->eeprom = kzalloc(sz, GFP_KERNEL);
405
276
        if (!priv->eeprom) {
427
298
                if (ret) {
428
299
                        IWL_ERR(priv, "Failed to initialize OTP access.\n");
429
300
                        ret = -ENOENT;
430
 
                        goto done;
 
301
                        goto err;
431
302
                }
432
303
                _iwl_write32(priv, CSR_EEPROM_GP,
433
304
                             iwl_read32(priv, CSR_EEPROM_GP) &
434
305
                             ~CSR_EEPROM_GP_IF_OWNER_MSK);
435
 
 
436
 
                iwl_set_bit(priv, CSR_OTP_GP_REG,
 
306
                /* clear */
 
307
                _iwl_write32(priv, CSR_OTP_GP_REG,
 
308
                             iwl_read32(priv, CSR_OTP_GP_REG) |
437
309
                             CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
438
310
                             CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
439
 
                /* traversing the linked list if no shadow ram supported */
440
 
                if (!priv->cfg->shadow_ram_support) {
441
 
                        if (iwl_find_otp_image(priv, &validblockaddr)) {
442
 
                                ret = -ENOENT;
443
 
                                goto done;
444
 
                        }
445
 
                }
446
 
                for (addr = validblockaddr; addr < validblockaddr + sz;
447
 
                     addr += sizeof(u16)) {
448
 
                        u16 eeprom_data;
449
 
 
450
 
                        ret = iwl_read_otp_word(priv, addr, &eeprom_data);
451
 
                        if (ret)
452
 
                                goto done;
453
 
                        e[cache_addr / 2] = eeprom_data;
454
 
                        cache_addr += sizeof(u16);
 
311
 
 
312
                for (addr = 0; addr < sz; addr += sizeof(u16)) {
 
313
                        u32 r;
 
314
 
 
315
                        _iwl_write32(priv, CSR_EEPROM_REG,
 
316
                                     CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
 
317
 
 
318
                        ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
 
319
                                                  CSR_EEPROM_REG_READ_VALID_MSK,
 
320
                                                  IWL_EEPROM_ACCESS_TIMEOUT);
 
321
                        if (ret < 0) {
 
322
                                IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
 
323
                                goto done;
 
324
                        }
 
325
                        r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
 
326
                        /* check for ECC errors: */
 
327
                        otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
 
328
                        if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
 
329
                                /* stop in this case */
 
330
                                IWL_ERR(priv, "Uncorrectable OTP ECC error, Abort OTP read\n");
 
331
                                goto done;
 
332
                        }
 
333
                        if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
 
334
                                /* continue in this case */
 
335
                                _iwl_write32(priv, CSR_OTP_GP_REG,
 
336
                                             iwl_read32(priv, CSR_OTP_GP_REG) |
 
337
                                             CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
 
338
                                IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
 
339
                        }
 
340
                        e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
455
341
                }
456
342
        } else {
457
343
                /* eeprom is an array of 16bit values */