tpm_infineon.c (b4ed3e3cbb312869929cf4528d71e52629a6cacb) | tpm_infineon.c (e659a3fe2027b19ecd8abb7ad79253672763454b) |
---|---|
1/* 2 * Description: 3 * Device Driver for the Infineon Technologies 4 * SLD 9630 TT 1.1 and SLB 9635 TT 1.2 Trusted Platform Module 5 * Specifications at www.trustedcomputinggroup.org 6 * 7 * Copyright (C) 2005, Marcel Selhorst <selhorst@crypto.rub.de> 8 * Applied Data Security Group, Ruhr-University Bochum, Germany --- 129 unchanged lines hidden (view full) --- 138 status = inb(chip->vendor->base + STAT); 139 /* check the status-register if wait_for_bit is set */ 140 if (status & 1 << wait_for_bit) 141 break; 142 msleep(TPM_MSLEEP_TIME); 143 } 144 if (i == TPM_MAX_TRIES) { /* timeout occurs */ 145 if (wait_for_bit == STAT_XFE) | 1/* 2 * Description: 3 * Device Driver for the Infineon Technologies 4 * SLD 9630 TT 1.1 and SLB 9635 TT 1.2 Trusted Platform Module 5 * Specifications at www.trustedcomputinggroup.org 6 * 7 * Copyright (C) 2005, Marcel Selhorst <selhorst@crypto.rub.de> 8 * Applied Data Security Group, Ruhr-University Bochum, Germany --- 129 unchanged lines hidden (view full) --- 138 status = inb(chip->vendor->base + STAT); 139 /* check the status-register if wait_for_bit is set */ 140 if (status & 1 << wait_for_bit) 141 break; 142 msleep(TPM_MSLEEP_TIME); 143 } 144 if (i == TPM_MAX_TRIES) { /* timeout occurs */ 145 if (wait_for_bit == STAT_XFE) |
146 dev_err(&chip->pci_dev->dev, | 146 dev_err(chip->dev, |
147 "Timeout in wait(STAT_XFE)\n"); 148 if (wait_for_bit == STAT_RDA) | 147 "Timeout in wait(STAT_XFE)\n"); 148 if (wait_for_bit == STAT_RDA) |
149 dev_err(&chip->pci_dev->dev, | 149 dev_err(chip->dev, |
150 "Timeout in wait(STAT_RDA)\n"); 151 return -EIO; 152 } 153 return 0; 154}; 155 156static void wait_and_send(struct tpm_chip *chip, u8 sendbyte) 157{ --- 7 unchanged lines hidden (view full) --- 165 creation. Set the maximum number of WTX-packages in the definitions 166 above, if the number is reached, the waiting-time will be denied 167 and the TPM command has to be resend. 168 */ 169 170static void tpm_wtx(struct tpm_chip *chip) 171{ 172 number_of_wtx++; | 150 "Timeout in wait(STAT_RDA)\n"); 151 return -EIO; 152 } 153 return 0; 154}; 155 156static void wait_and_send(struct tpm_chip *chip, u8 sendbyte) 157{ --- 7 unchanged lines hidden (view full) --- 165 creation. Set the maximum number of WTX-packages in the definitions 166 above, if the number is reached, the waiting-time will be denied 167 and the TPM command has to be resend. 168 */ 169 170static void tpm_wtx(struct tpm_chip *chip) 171{ 172 number_of_wtx++; |
173 dev_info(&chip->pci_dev->dev, "Granting WTX (%02d / %02d)\n", | 173 dev_info(chip->dev, "Granting WTX (%02d / %02d)\n", |
174 number_of_wtx, TPM_MAX_WTX_PACKAGES); 175 wait_and_send(chip, TPM_VL_VER); 176 wait_and_send(chip, TPM_CTRL_WTX); 177 wait_and_send(chip, 0x00); 178 wait_and_send(chip, 0x00); 179 msleep(TPM_WTX_MSLEEP_TIME); 180} 181 182static void tpm_wtx_abort(struct tpm_chip *chip) 183{ | 174 number_of_wtx, TPM_MAX_WTX_PACKAGES); 175 wait_and_send(chip, TPM_VL_VER); 176 wait_and_send(chip, TPM_CTRL_WTX); 177 wait_and_send(chip, 0x00); 178 wait_and_send(chip, 0x00); 179 msleep(TPM_WTX_MSLEEP_TIME); 180} 181 182static void tpm_wtx_abort(struct tpm_chip *chip) 183{ |
184 dev_info(&chip->pci_dev->dev, "Aborting WTX\n"); | 184 dev_info(chip->dev, "Aborting WTX\n"); |
185 wait_and_send(chip, TPM_VL_VER); 186 wait_and_send(chip, TPM_CTRL_WTX_ABORT); 187 wait_and_send(chip, 0x00); 188 wait_and_send(chip, 0x00); 189 number_of_wtx = 0; 190 msleep(TPM_WTX_MSLEEP_TIME); 191} 192 --- 8 unchanged lines hidden (view full) --- 201 for (i = 0; i < 4; i++) { 202 ret = wait(chip, STAT_RDA); 203 if (ret) 204 return -EIO; 205 buf[i] = inb(chip->vendor->base + RDFIFO); 206 } 207 208 if (buf[0] != TPM_VL_VER) { | 185 wait_and_send(chip, TPM_VL_VER); 186 wait_and_send(chip, TPM_CTRL_WTX_ABORT); 187 wait_and_send(chip, 0x00); 188 wait_and_send(chip, 0x00); 189 number_of_wtx = 0; 190 msleep(TPM_WTX_MSLEEP_TIME); 191} 192 --- 8 unchanged lines hidden (view full) --- 201 for (i = 0; i < 4; i++) { 202 ret = wait(chip, STAT_RDA); 203 if (ret) 204 return -EIO; 205 buf[i] = inb(chip->vendor->base + RDFIFO); 206 } 207 208 if (buf[0] != TPM_VL_VER) { |
209 dev_err(&chip->pci_dev->dev, | 209 dev_err(chip->dev, |
210 "Wrong transport protocol implementation!\n"); 211 return -EIO; 212 } 213 214 if (buf[1] == TPM_CTRL_DATA) { 215 /* size of the data received */ 216 size = ((buf[2] << 8) | buf[3]); 217 218 for (i = 0; i < size; i++) { 219 wait(chip, STAT_RDA); 220 buf[i] = inb(chip->vendor->base + RDFIFO); 221 } 222 223 if ((size == 0x6D00) && (buf[1] == 0x80)) { | 210 "Wrong transport protocol implementation!\n"); 211 return -EIO; 212 } 213 214 if (buf[1] == TPM_CTRL_DATA) { 215 /* size of the data received */ 216 size = ((buf[2] << 8) | buf[3]); 217 218 for (i = 0; i < size; i++) { 219 wait(chip, STAT_RDA); 220 buf[i] = inb(chip->vendor->base + RDFIFO); 221 } 222 223 if ((size == 0x6D00) && (buf[1] == 0x80)) { |
224 dev_err(&chip->pci_dev->dev, | 224 dev_err(chip->dev, |
225 "Error handling on vendor layer!\n"); 226 return -EIO; 227 } 228 229 for (i = 0; i < size; i++) 230 buf[i] = buf[i + 6]; 231 232 size = size - 6; 233 return size; 234 } 235 236 if (buf[1] == TPM_CTRL_WTX) { | 225 "Error handling on vendor layer!\n"); 226 return -EIO; 227 } 228 229 for (i = 0; i < size; i++) 230 buf[i] = buf[i + 6]; 231 232 size = size - 6; 233 return size; 234 } 235 236 if (buf[1] == TPM_CTRL_WTX) { |
237 dev_info(&chip->pci_dev->dev, "WTX-package received\n"); | 237 dev_info(chip->dev, "WTX-package received\n"); |
238 if (number_of_wtx < TPM_MAX_WTX_PACKAGES) { 239 tpm_wtx(chip); 240 goto recv_begin; 241 } else { 242 tpm_wtx_abort(chip); 243 goto recv_begin; 244 } 245 } 246 247 if (buf[1] == TPM_CTRL_WTX_ABORT_ACK) { | 238 if (number_of_wtx < TPM_MAX_WTX_PACKAGES) { 239 tpm_wtx(chip); 240 goto recv_begin; 241 } else { 242 tpm_wtx_abort(chip); 243 goto recv_begin; 244 } 245 } 246 247 if (buf[1] == TPM_CTRL_WTX_ABORT_ACK) { |
248 dev_info(&chip->pci_dev->dev, "WTX-abort acknowledged\n"); | 248 dev_info(chip->dev, "WTX-abort acknowledged\n"); |
249 return size; 250 } 251 252 if (buf[1] == TPM_CTRL_ERROR) { | 249 return size; 250 } 251 252 if (buf[1] == TPM_CTRL_ERROR) { |
253 dev_err(&chip->pci_dev->dev, "ERROR-package received:\n"); | 253 dev_err(chip->dev, "ERROR-package received:\n"); |
254 if (buf[4] == TPM_INF_NAK) | 254 if (buf[4] == TPM_INF_NAK) |
255 dev_err(&chip->pci_dev->dev, | 255 dev_err(chip->dev, |
256 "-> Negative acknowledgement" 257 " - retransmit command!\n"); 258 return -EIO; 259 } 260 return -EIO; 261} 262 263static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count) 264{ 265 int i; 266 int ret; 267 u8 count_high, count_low, count_4, count_3, count_2, count_1; 268 269 /* Disabling Reset, LP and IRQC */ 270 outb(RESET_LP_IRQC_DISABLE, chip->vendor->base + CMD); 271 272 ret = empty_fifo(chip, 1); 273 if (ret) { | 256 "-> Negative acknowledgement" 257 " - retransmit command!\n"); 258 return -EIO; 259 } 260 return -EIO; 261} 262 263static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count) 264{ 265 int i; 266 int ret; 267 u8 count_high, count_low, count_4, count_3, count_2, count_1; 268 269 /* Disabling Reset, LP and IRQC */ 270 outb(RESET_LP_IRQC_DISABLE, chip->vendor->base + CMD); 271 272 ret = empty_fifo(chip, 1); 273 if (ret) { |
274 dev_err(&chip->pci_dev->dev, "Timeout while clearing FIFO\n"); | 274 dev_err(chip->dev, "Timeout while clearing FIFO\n"); |
275 return -EIO; 276 } 277 278 ret = wait(chip, STAT_XFE); 279 if (ret) 280 return -EIO; 281 282 count_4 = (count & 0xff000000) >> 24; --- 206 unchanged lines hidden (view full) --- 489 "product id %02x%02x" 490 "%s\n", 491 TPM_INF_ADDR, 492 tpm_inf.base, 493 version[0], version[1], 494 vendorid[0], vendorid[1], 495 productid[0], productid[1], chipname); 496 | 275 return -EIO; 276 } 277 278 ret = wait(chip, STAT_XFE); 279 if (ret) 280 return -EIO; 281 282 count_4 = (count & 0xff000000) >> 24; --- 206 unchanged lines hidden (view full) --- 489 "product id %02x%02x" 490 "%s\n", 491 TPM_INF_ADDR, 492 tpm_inf.base, 493 version[0], version[1], 494 vendorid[0], vendorid[1], 495 productid[0], productid[1], chipname); 496 |
497 rc = tpm_register_hardware(pci_dev, &tpm_inf); | 497 rc = tpm_register_hardware(&pci_dev->dev, &tpm_inf); |
498 if (rc < 0) 499 goto error; 500 return 0; 501 } else { 502 dev_info(&pci_dev->dev, "No Infineon TPM found!\n"); 503error: 504 pnp_unregister_driver(&tpm_inf_pnp); 505error2: 506 pci_disable_device(pci_dev); 507 pnp_registered = 0; 508 return -ENODEV; 509 } 510} 511 | 498 if (rc < 0) 499 goto error; 500 return 0; 501 } else { 502 dev_info(&pci_dev->dev, "No Infineon TPM found!\n"); 503error: 504 pnp_unregister_driver(&tpm_inf_pnp); 505error2: 506 pci_disable_device(pci_dev); 507 pnp_registered = 0; 508 return -ENODEV; 509 } 510} 511 |
512static __devexit void tpm_inf_remove(struct pci_dev* pci_dev) 513{ 514 struct tpm_chip* chip = pci_get_drvdata(pci_dev); 515 516 if( chip ) 517 tpm_remove_hardware(chip->dev); 518} 519 |
|
512static struct pci_device_id tpm_pci_tbl[] __devinitdata = { 513 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)}, 514 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)}, 515 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)}, 516 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)}, 517 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)}, 518 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0)}, 519 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1)}, 520 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_2)}, 521 {0,} 522}; 523 524MODULE_DEVICE_TABLE(pci, tpm_pci_tbl); 525 526static struct pci_driver inf_pci_driver = { 527 .name = "tpm_inf", 528 .id_table = tpm_pci_tbl, 529 .probe = tpm_inf_probe, | 520static struct pci_device_id tpm_pci_tbl[] __devinitdata = { 521 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)}, 522 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)}, 523 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)}, 524 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)}, 525 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)}, 526 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0)}, 527 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1)}, 528 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_2)}, 529 {0,} 530}; 531 532MODULE_DEVICE_TABLE(pci, tpm_pci_tbl); 533 534static struct pci_driver inf_pci_driver = { 535 .name = "tpm_inf", 536 .id_table = tpm_pci_tbl, 537 .probe = tpm_inf_probe, |
530 .remove = __devexit_p(tpm_remove), | 538 .remove = __devexit_p(tpm_inf_remove), |
531 .suspend = tpm_pm_suspend, 532 .resume = tpm_pm_resume, 533}; 534 535static int __init init_inf(void) 536{ 537 return pci_register_driver(&inf_pci_driver); 538} --- 15 unchanged lines hidden --- | 539 .suspend = tpm_pm_suspend, 540 .resume = tpm_pm_resume, 541}; 542 543static int __init init_inf(void) 544{ 545 return pci_register_driver(&inf_pci_driver); 546} --- 15 unchanged lines hidden --- |