aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/mic/host
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-11-05 01:15:15 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-11-05 01:15:15 -0500
commit8e483ed1342a4ea45b70f0f33ac54eff7a33d918 (patch)
tree66c9f9ad196581966bdb06802e11e9856b1c0779 /drivers/misc/mic/host
parente880e87488d5bbf630dd716e6de8a53585614568 (diff)
parente2d8680741edec84f843f783a7f4a44418b818d7 (diff)
Merge tag 'char-misc-4.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver updates from Greg KH: "Here is the big char/misc driver update for 4.4-rc1. Lots of different driver and subsystem updates, hwtracing being the largest with the addition of some new platforms that are now supported. Full details in the shortlog. All of these have been in linux-next for a long time with no reported issues" * tag 'char-misc-4.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (181 commits) fpga: socfpga: Fix check of return value of devm_request_irq lkdtm: fix ACCESS_USERSPACE test mcb: Destroy IDA on module unload mcb: Do not return zero on error path in mcb_pci_probe() mei: bus: set the device name before running fixup mei: bus: use correct lock ordering mei: Fix debugfs filename in error output char: ipmi: ipmi_ssif: Replace timeval with timespec64 fpga: zynq-fpga: Fix issue with drvdata being overwritten. fpga manager: remove unnecessary null pointer checks fpga manager: ensure lifetime with of_fpga_mgr_get fpga: zynq-fpga: Change fw format to handle bin instead of bit. fpga: zynq-fpga: Fix unbalanced clock handling misc: sram: partition base address belongs to __iomem space coresight: etm3x: adding documentation for sysFS's cpu interface vme: 8-bit status/id takes 256 values, not 255 fpga manager: Adding FPGA Manager support for Xilinx Zynq 7000 ARM: zynq: dt: Updated devicetree for Zynq 7000 platform. ARM: dt: fpga: Added binding docs for Xilinx Zynq FPGA manager. ver_linux: proc/modules, limit text processing to 'sed' ...
Diffstat (limited to 'drivers/misc/mic/host')
-rw-r--r--drivers/misc/mic/host/Makefile1
-rw-r--r--drivers/misc/mic/host/mic_boot.c317
-rw-r--r--drivers/misc/mic/host/mic_debugfs.c114
-rw-r--r--drivers/misc/mic/host/mic_device.h88
-rw-r--r--drivers/misc/mic/host/mic_fops.c4
-rw-r--r--drivers/misc/mic/host/mic_intr.c46
-rw-r--r--drivers/misc/mic/host/mic_main.c223
-rw-r--r--drivers/misc/mic/host/mic_smpt.c30
-rw-r--r--drivers/misc/mic/host/mic_sysfs.c459
-rw-r--r--drivers/misc/mic/host/mic_virtio.c17
-rw-r--r--drivers/misc/mic/host/mic_virtio.h2
-rw-r--r--drivers/misc/mic/host/mic_x100.c46
12 files changed, 204 insertions, 1143 deletions
diff --git a/drivers/misc/mic/host/Makefile b/drivers/misc/mic/host/Makefile
index c2197f999394..004d3db0f990 100644
--- a/drivers/misc/mic/host/Makefile
+++ b/drivers/misc/mic/host/Makefile
@@ -5,7 +5,6 @@
5obj-$(CONFIG_INTEL_MIC_HOST) += mic_host.o 5obj-$(CONFIG_INTEL_MIC_HOST) += mic_host.o
6mic_host-objs := mic_main.o 6mic_host-objs := mic_main.o
7mic_host-objs += mic_x100.o 7mic_host-objs += mic_x100.o
8mic_host-objs += mic_sysfs.o
9mic_host-objs += mic_smpt.o 8mic_host-objs += mic_smpt.o
10mic_host-objs += mic_intr.o 9mic_host-objs += mic_intr.o
11mic_host-objs += mic_boot.o 10mic_host-objs += mic_boot.o
diff --git a/drivers/misc/mic/host/mic_boot.c b/drivers/misc/mic/host/mic_boot.c
index e5f6a5e7bca1..7845564dff64 100644
--- a/drivers/misc/mic/host/mic_boot.c
+++ b/drivers/misc/mic/host/mic_boot.c
@@ -22,9 +22,9 @@
22#include <linux/firmware.h> 22#include <linux/firmware.h>
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/kmod.h> 24#include <linux/kmod.h>
25
26#include <linux/mic_common.h> 25#include <linux/mic_common.h>
27#include <linux/mic_bus.h> 26#include <linux/mic_bus.h>
27#include "../bus/scif_bus.h"
28#include "../common/mic_dev.h" 28#include "../common/mic_dev.h"
29#include "mic_device.h" 29#include "mic_device.h"
30#include "mic_smpt.h" 30#include "mic_smpt.h"
@@ -99,7 +99,7 @@ static int __mic_dma_map_sg(struct device *dev, struct scatterlist *sg,
99 int i, j, ret; 99 int i, j, ret;
100 dma_addr_t da; 100 dma_addr_t da;
101 101
102 ret = dma_map_sg(mdev->sdev->parent, sg, nents, dir); 102 ret = dma_map_sg(&mdev->pdev->dev, sg, nents, dir);
103 if (ret <= 0) 103 if (ret <= 0)
104 return 0; 104 return 0;
105 105
@@ -115,7 +115,7 @@ err:
115 mic_unmap(mdev, sg_dma_address(s), s->length); 115 mic_unmap(mdev, sg_dma_address(s), s->length);
116 sg_dma_address(s) = mic_to_dma_addr(mdev, sg_dma_address(s)); 116 sg_dma_address(s) = mic_to_dma_addr(mdev, sg_dma_address(s));
117 } 117 }
118 dma_unmap_sg(mdev->sdev->parent, sg, nents, dir); 118 dma_unmap_sg(&mdev->pdev->dev, sg, nents, dir);
119 return 0; 119 return 0;
120} 120}
121 121
@@ -135,7 +135,7 @@ static void __mic_dma_unmap_sg(struct device *dev,
135 mic_unmap(mdev, sg_dma_address(s), s->length); 135 mic_unmap(mdev, sg_dma_address(s), s->length);
136 sg_dma_address(s) = da; 136 sg_dma_address(s) = da;
137 } 137 }
138 dma_unmap_sg(mdev->sdev->parent, sg, nents, dir); 138 dma_unmap_sg(&mdev->pdev->dev, sg, nents, dir);
139} 139}
140 140
141static struct dma_map_ops __mic_dma_ops = { 141static struct dma_map_ops __mic_dma_ops = {
@@ -270,48 +270,13 @@ static struct mbus_hw_ops mbus_hw_ops = {
270 .ack_interrupt = _mic_ack_interrupt, 270 .ack_interrupt = _mic_ack_interrupt,
271}; 271};
272 272
273/**
274 * mic_reset - Reset the MIC device.
275 * @mdev: pointer to mic_device instance
276 */
277static void mic_reset(struct mic_device *mdev)
278{
279 int i;
280
281#define MIC_RESET_TO (45)
282
283 reinit_completion(&mdev->reset_wait);
284 mdev->ops->reset_fw_ready(mdev);
285 mdev->ops->reset(mdev);
286
287 for (i = 0; i < MIC_RESET_TO; i++) {
288 if (mdev->ops->is_fw_ready(mdev))
289 goto done;
290 /*
291 * Resets typically take 10s of seconds to complete.
292 * Since an MMIO read is required to check if the
293 * firmware is ready or not, a 1 second delay works nicely.
294 */
295 msleep(1000);
296 }
297 mic_set_state(mdev, MIC_RESET_FAILED);
298done:
299 complete_all(&mdev->reset_wait);
300}
301
302/* Initialize the MIC bootparams */ 273/* Initialize the MIC bootparams */
303void mic_bootparam_init(struct mic_device *mdev) 274void mic_bootparam_init(struct mic_device *mdev)
304{ 275{
305 struct mic_bootparam *bootparam = mdev->dp; 276 struct mic_bootparam *bootparam = mdev->dp;
306 277
307 bootparam->magic = cpu_to_le32(MIC_MAGIC); 278 bootparam->magic = cpu_to_le32(MIC_MAGIC);
308 bootparam->c2h_shutdown_db = mdev->shutdown_db;
309 bootparam->h2c_shutdown_db = -1;
310 bootparam->h2c_config_db = -1; 279 bootparam->h2c_config_db = -1;
311 bootparam->shutdown_status = 0;
312 bootparam->shutdown_card = 0;
313 /* Total nodes = number of MICs + 1 for self node */
314 bootparam->tot_nodes = atomic_read(&g_num_mics) + 1;
315 bootparam->node_id = mdev->id + 1; 280 bootparam->node_id = mdev->id + 1;
316 bootparam->scif_host_dma_addr = 0x0; 281 bootparam->scif_host_dma_addr = 0x0;
317 bootparam->scif_card_dma_addr = 0x0; 282 bootparam->scif_card_dma_addr = 0x0;
@@ -319,6 +284,26 @@ void mic_bootparam_init(struct mic_device *mdev)
319 bootparam->h2c_scif_db = -1; 284 bootparam->h2c_scif_db = -1;
320} 285}
321 286
287static inline struct mic_device *cosmdev_to_mdev(struct cosm_device *cdev)
288{
289 return dev_get_drvdata(cdev->dev.parent);
290}
291
292static void _mic_reset(struct cosm_device *cdev)
293{
294 struct mic_device *mdev = cosmdev_to_mdev(cdev);
295
296 mdev->ops->reset_fw_ready(mdev);
297 mdev->ops->reset(mdev);
298}
299
300static bool _mic_ready(struct cosm_device *cdev)
301{
302 struct mic_device *mdev = cosmdev_to_mdev(cdev);
303
304 return mdev->ops->is_fw_ready(mdev);
305}
306
322/** 307/**
323 * mic_request_dma_chans - Request DMA channels 308 * mic_request_dma_chans - Request DMA channels
324 * @mdev: pointer to mic_device instance 309 * @mdev: pointer to mic_device instance
@@ -336,14 +321,14 @@ static int mic_request_dma_chans(struct mic_device *mdev)
336 321
337 do { 322 do {
338 chan = dma_request_channel(mask, mdev->ops->dma_filter, 323 chan = dma_request_channel(mask, mdev->ops->dma_filter,
339 mdev->sdev->parent); 324 &mdev->pdev->dev);
340 if (chan) { 325 if (chan) {
341 mdev->dma_ch[mdev->num_dma_ch++] = chan; 326 mdev->dma_ch[mdev->num_dma_ch++] = chan;
342 if (mdev->num_dma_ch >= MIC_MAX_DMA_CHAN) 327 if (mdev->num_dma_ch >= MIC_MAX_DMA_CHAN)
343 break; 328 break;
344 } 329 }
345 } while (chan); 330 } while (chan);
346 dev_info(mdev->sdev->parent, "DMA channels # %d\n", mdev->num_dma_ch); 331 dev_info(&mdev->pdev->dev, "DMA channels # %d\n", mdev->num_dma_ch);
347 return mdev->num_dma_ch; 332 return mdev->num_dma_ch;
348} 333}
349 334
@@ -365,34 +350,24 @@ static void mic_free_dma_chans(struct mic_device *mdev)
365} 350}
366 351
367/** 352/**
368 * mic_start - Start the MIC. 353 * _mic_start - Start the MIC.
369 * @mdev: pointer to mic_device instance 354 * @cdev: pointer to cosm_device instance
370 * @buf: buffer containing boot string including firmware/ramdisk path. 355 * @id: MIC device id/index provided by COSM used in other drivers like SCIF
371 * 356 *
372 * This function prepares an MIC for boot and initiates boot. 357 * This function prepares an MIC for boot and initiates boot.
373 * RETURNS: An appropriate -ERRNO error value on error, or zero for success. 358 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
359 *
360 * For all cosm_hw_ops the caller holds a mutex to ensure serialization.
374 */ 361 */
375int mic_start(struct mic_device *mdev, const char *buf) 362static int _mic_start(struct cosm_device *cdev, int id)
376{ 363{
364 struct mic_device *mdev = cosmdev_to_mdev(cdev);
377 int rc; 365 int rc;
378 mutex_lock(&mdev->mic_mutex); 366
379 mic_bootparam_init(mdev); 367 mic_bootparam_init(mdev);
380retry: 368 mdev->dma_mbdev = mbus_register_device(&mdev->pdev->dev,
381 if (MIC_OFFLINE != mdev->state) {
382 rc = -EINVAL;
383 goto unlock_ret;
384 }
385 if (!mdev->ops->is_fw_ready(mdev)) {
386 mic_reset(mdev);
387 /*
388 * The state will either be MIC_OFFLINE if the reset succeeded
389 * or MIC_RESET_FAILED if the firmware reset failed.
390 */
391 goto retry;
392 }
393 mdev->dma_mbdev = mbus_register_device(mdev->sdev->parent,
394 MBUS_DEV_DMA_HOST, &mic_dma_ops, 369 MBUS_DEV_DMA_HOST, &mic_dma_ops,
395 &mbus_hw_ops, mdev->mmio.va); 370 &mbus_hw_ops, id, mdev->mmio.va);
396 if (IS_ERR(mdev->dma_mbdev)) { 371 if (IS_ERR(mdev->dma_mbdev)) {
397 rc = PTR_ERR(mdev->dma_mbdev); 372 rc = PTR_ERR(mdev->dma_mbdev);
398 goto unlock_ret; 373 goto unlock_ret;
@@ -401,16 +376,18 @@ retry:
401 rc = -ENODEV; 376 rc = -ENODEV;
402 goto dma_remove; 377 goto dma_remove;
403 } 378 }
404 mdev->scdev = scif_register_device(mdev->sdev->parent, MIC_SCIF_DEV, 379 mdev->scdev = scif_register_device(&mdev->pdev->dev, MIC_SCIF_DEV,
405 &__mic_dma_ops, &scif_hw_ops, 380 &__mic_dma_ops, &scif_hw_ops,
406 mdev->id + 1, 0, &mdev->mmio, 381 id + 1, 0, &mdev->mmio,
407 &mdev->aper, mdev->dp, NULL, 382 &mdev->aper, mdev->dp, NULL,
408 mdev->dma_ch, mdev->num_dma_ch); 383 mdev->dma_ch, mdev->num_dma_ch,
384 true);
409 if (IS_ERR(mdev->scdev)) { 385 if (IS_ERR(mdev->scdev)) {
410 rc = PTR_ERR(mdev->scdev); 386 rc = PTR_ERR(mdev->scdev);
411 goto dma_free; 387 goto dma_free;
412 } 388 }
413 rc = mdev->ops->load_mic_fw(mdev, buf); 389
390 rc = mdev->ops->load_mic_fw(mdev, NULL);
414 if (rc) 391 if (rc)
415 goto scif_remove; 392 goto scif_remove;
416 mic_smpt_restore(mdev); 393 mic_smpt_restore(mdev);
@@ -419,7 +396,6 @@ retry:
419 mdev->ops->write_spad(mdev, MIC_DPLO_SPAD, mdev->dp_dma_addr); 396 mdev->ops->write_spad(mdev, MIC_DPLO_SPAD, mdev->dp_dma_addr);
420 mdev->ops->write_spad(mdev, MIC_DPHI_SPAD, mdev->dp_dma_addr >> 32); 397 mdev->ops->write_spad(mdev, MIC_DPHI_SPAD, mdev->dp_dma_addr >> 32);
421 mdev->ops->send_firmware_intr(mdev); 398 mdev->ops->send_firmware_intr(mdev);
422 mic_set_state(mdev, MIC_ONLINE);
423 goto unlock_ret; 399 goto unlock_ret;
424scif_remove: 400scif_remove:
425 scif_unregister_device(mdev->scdev); 401 scif_unregister_device(mdev->scdev);
@@ -428,198 +404,79 @@ dma_free:
428dma_remove: 404dma_remove:
429 mbus_unregister_device(mdev->dma_mbdev); 405 mbus_unregister_device(mdev->dma_mbdev);
430unlock_ret: 406unlock_ret:
431 mutex_unlock(&mdev->mic_mutex);
432 return rc; 407 return rc;
433} 408}
434 409
435/** 410/**
436 * mic_stop - Prepare the MIC for reset and trigger reset. 411 * _mic_stop - Prepare the MIC for reset and trigger reset.
437 * @mdev: pointer to mic_device instance 412 * @cdev: pointer to cosm_device instance
438 * @force: force a MIC to reset even if it is already offline. 413 * @force: force a MIC to reset even if it is already offline.
439 * 414 *
440 * RETURNS: None. 415 * RETURNS: None.
441 */ 416 */
442void mic_stop(struct mic_device *mdev, bool force) 417static void _mic_stop(struct cosm_device *cdev, bool force)
443{
444 mutex_lock(&mdev->mic_mutex);
445 if (MIC_OFFLINE != mdev->state || force) {
446 scif_unregister_device(mdev->scdev);
447 mic_virtio_reset_devices(mdev);
448 mic_free_dma_chans(mdev);
449 mbus_unregister_device(mdev->dma_mbdev);
450 mic_bootparam_init(mdev);
451 mic_reset(mdev);
452 if (MIC_RESET_FAILED == mdev->state)
453 goto unlock;
454 mic_set_shutdown_status(mdev, MIC_NOP);
455 if (MIC_SUSPENDED != mdev->state)
456 mic_set_state(mdev, MIC_OFFLINE);
457 }
458unlock:
459 mutex_unlock(&mdev->mic_mutex);
460}
461
462/**
463 * mic_shutdown - Initiate MIC shutdown.
464 * @mdev: pointer to mic_device instance
465 *
466 * RETURNS: None.
467 */
468void mic_shutdown(struct mic_device *mdev)
469{ 418{
470 struct mic_bootparam *bootparam = mdev->dp; 419 struct mic_device *mdev = cosmdev_to_mdev(cdev);
471 s8 db = bootparam->h2c_shutdown_db;
472
473 mutex_lock(&mdev->mic_mutex);
474 if (MIC_ONLINE == mdev->state && db != -1) {
475 bootparam->shutdown_card = 1;
476 mdev->ops->send_intr(mdev, db);
477 mic_set_state(mdev, MIC_SHUTTING_DOWN);
478 }
479 mutex_unlock(&mdev->mic_mutex);
480}
481
482/**
483 * mic_shutdown_work - Handle shutdown interrupt from MIC.
484 * @work: The work structure.
485 *
486 * This work is scheduled whenever the host has received a shutdown
487 * interrupt from the MIC.
488 */
489void mic_shutdown_work(struct work_struct *work)
490{
491 struct mic_device *mdev = container_of(work, struct mic_device,
492 shutdown_work);
493 struct mic_bootparam *bootparam = mdev->dp;
494
495 mutex_lock(&mdev->mic_mutex);
496 mic_set_shutdown_status(mdev, bootparam->shutdown_status);
497 bootparam->shutdown_status = 0;
498 420
499 /* 421 /*
500 * if state is MIC_SUSPENDED, OSPM suspend is in progress. We do not 422 * Since SCIF handles card shutdown and reset (using COSM), it will
501 * change the state here so as to prevent users from booting the card 423 * will be the first to be registered and the last to be
502 * during and after the suspend operation. 424 * unregistered.
503 */ 425 */
504 if (MIC_SHUTTING_DOWN != mdev->state && 426 mic_virtio_reset_devices(mdev);
505 MIC_SUSPENDED != mdev->state) 427 scif_unregister_device(mdev->scdev);
506 mic_set_state(mdev, MIC_SHUTTING_DOWN); 428 mic_free_dma_chans(mdev);
507 mutex_unlock(&mdev->mic_mutex); 429 mbus_unregister_device(mdev->dma_mbdev);
430 mic_bootparam_init(mdev);
508} 431}
509 432
510/** 433static ssize_t _mic_family(struct cosm_device *cdev, char *buf)
511 * mic_reset_trigger_work - Trigger MIC reset.
512 * @work: The work structure.
513 *
514 * This work is scheduled whenever the host wants to reset the MIC.
515 */
516void mic_reset_trigger_work(struct work_struct *work)
517{ 434{
518 struct mic_device *mdev = container_of(work, struct mic_device, 435 struct mic_device *mdev = cosmdev_to_mdev(cdev);
519 reset_trigger_work); 436 static const char *family[MIC_FAMILY_LAST] = { "x100", "Unknown" };
520 437
521 mic_stop(mdev, false); 438 return scnprintf(buf, PAGE_SIZE, "%s\n", family[mdev->family]);
522} 439}
523 440
524/** 441static ssize_t _mic_stepping(struct cosm_device *cdev, char *buf)
525 * mic_complete_resume - Complete MIC Resume after an OSPM suspend/hibernate
526 * event.
527 * @mdev: pointer to mic_device instance
528 *
529 * RETURNS: None.
530 */
531void mic_complete_resume(struct mic_device *mdev)
532{ 442{
533 if (mdev->state != MIC_SUSPENDED) { 443 struct mic_device *mdev = cosmdev_to_mdev(cdev);
534 dev_warn(mdev->sdev->parent, "state %d should be %d\n", 444 const char *string = "??";
535 mdev->state, MIC_SUSPENDED);
536 return;
537 }
538
539 /* Make sure firmware is ready */
540 if (!mdev->ops->is_fw_ready(mdev))
541 mic_stop(mdev, true);
542 445
543 mutex_lock(&mdev->mic_mutex); 446 switch (mdev->stepping) {
544 mic_set_state(mdev, MIC_OFFLINE); 447 case MIC_A0_STEP:
545 mutex_unlock(&mdev->mic_mutex); 448 string = "A0";
546}
547
548/**
549 * mic_prepare_suspend - Handle suspend notification for the MIC device.
550 * @mdev: pointer to mic_device instance
551 *
552 * RETURNS: None.
553 */
554void mic_prepare_suspend(struct mic_device *mdev)
555{
556 unsigned long timeout;
557
558#define MIC_SUSPEND_TIMEOUT (60 * HZ)
559
560 mutex_lock(&mdev->mic_mutex);
561 switch (mdev->state) {
562 case MIC_OFFLINE:
563 /*
564 * Card is already offline. Set state to MIC_SUSPENDED
565 * to prevent users from booting the card.
566 */
567 mic_set_state(mdev, MIC_SUSPENDED);
568 mutex_unlock(&mdev->mic_mutex);
569 break; 449 break;
570 case MIC_ONLINE: 450 case MIC_B0_STEP:
571 /* 451 string = "B0";
572 * Card is online. Set state to MIC_SUSPENDING and notify 452 break;
573 * MIC user space daemon which will issue card 453 case MIC_B1_STEP:
574 * shutdown and reset. 454 string = "B1";
575 */
576 mic_set_state(mdev, MIC_SUSPENDING);
577 mutex_unlock(&mdev->mic_mutex);
578 timeout = wait_for_completion_timeout(&mdev->reset_wait,
579 MIC_SUSPEND_TIMEOUT);
580 /* Force reset the card if the shutdown completion timed out */
581 if (!timeout) {
582 mutex_lock(&mdev->mic_mutex);
583 mic_set_state(mdev, MIC_SUSPENDED);
584 mutex_unlock(&mdev->mic_mutex);
585 mic_stop(mdev, true);
586 }
587 break; 455 break;
588 case MIC_SHUTTING_DOWN: 456 case MIC_C0_STEP:
589 /* 457 string = "C0";
590 * Card is shutting down. Set state to MIC_SUSPENDED
591 * to prevent further boot of the card.
592 */
593 mic_set_state(mdev, MIC_SUSPENDED);
594 mutex_unlock(&mdev->mic_mutex);
595 timeout = wait_for_completion_timeout(&mdev->reset_wait,
596 MIC_SUSPEND_TIMEOUT);
597 /* Force reset the card if the shutdown completion timed out */
598 if (!timeout)
599 mic_stop(mdev, true);
600 break; 458 break;
601 default: 459 default:
602 mutex_unlock(&mdev->mic_mutex);
603 break; 460 break;
604 } 461 }
462 return scnprintf(buf, PAGE_SIZE, "%s\n", string);
605} 463}
606 464
607/** 465static struct mic_mw *_mic_aper(struct cosm_device *cdev)
608 * mic_suspend - Initiate MIC suspend. Suspend merely issues card shutdown.
609 * @mdev: pointer to mic_device instance
610 *
611 * RETURNS: None.
612 */
613void mic_suspend(struct mic_device *mdev)
614{ 466{
615 struct mic_bootparam *bootparam = mdev->dp; 467 struct mic_device *mdev = cosmdev_to_mdev(cdev);
616 s8 db = bootparam->h2c_shutdown_db;
617 468
618 mutex_lock(&mdev->mic_mutex); 469 return &mdev->aper;
619 if (MIC_SUSPENDING == mdev->state && db != -1) {
620 bootparam->shutdown_card = 1;
621 mdev->ops->send_intr(mdev, db);
622 mic_set_state(mdev, MIC_SUSPENDED);
623 }
624 mutex_unlock(&mdev->mic_mutex);
625} 470}
471
472struct cosm_hw_ops cosm_hw_ops = {
473 .reset = _mic_reset,
474 .force_reset = _mic_reset,
475 .post_reset = NULL,
476 .ready = _mic_ready,
477 .start = _mic_start,
478 .stop = _mic_stop,
479 .family = _mic_family,
480 .stepping = _mic_stepping,
481 .aper = _mic_aper,
482};
diff --git a/drivers/misc/mic/host/mic_debugfs.c b/drivers/misc/mic/host/mic_debugfs.c
index 3c9ea4896f3c..10581600777a 100644
--- a/drivers/misc/mic/host/mic_debugfs.c
+++ b/drivers/misc/mic/host/mic_debugfs.c
@@ -31,71 +31,6 @@
31/* Debugfs parent dir */ 31/* Debugfs parent dir */
32static struct dentry *mic_dbg; 32static struct dentry *mic_dbg;
33 33
34/**
35 * mic_log_buf_show - Display MIC kernel log buffer.
36 *
37 * log_buf addr/len is read from System.map by user space
38 * and populated in sysfs entries.
39 */
40static int mic_log_buf_show(struct seq_file *s, void *unused)
41{
42 void __iomem *log_buf_va;
43 int __iomem *log_buf_len_va;
44 struct mic_device *mdev = s->private;
45 void *kva;
46 int size;
47 unsigned long aper_offset;
48
49 if (!mdev || !mdev->log_buf_addr || !mdev->log_buf_len)
50 goto done;
51 /*
52 * Card kernel will never be relocated and any kernel text/data mapping
53 * can be translated to phys address by subtracting __START_KERNEL_map.
54 */
55 aper_offset = (unsigned long)mdev->log_buf_len - __START_KERNEL_map;
56 log_buf_len_va = mdev->aper.va + aper_offset;
57 aper_offset = (unsigned long)mdev->log_buf_addr - __START_KERNEL_map;
58 log_buf_va = mdev->aper.va + aper_offset;
59 size = ioread32(log_buf_len_va);
60
61 kva = kmalloc(size, GFP_KERNEL);
62 if (!kva)
63 goto done;
64 mutex_lock(&mdev->mic_mutex);
65 memcpy_fromio(kva, log_buf_va, size);
66 switch (mdev->state) {
67 case MIC_ONLINE:
68 /* Fall through */
69 case MIC_SHUTTING_DOWN:
70 seq_write(s, kva, size);
71 break;
72 default:
73 break;
74 }
75 mutex_unlock(&mdev->mic_mutex);
76 kfree(kva);
77done:
78 return 0;
79}
80
81static int mic_log_buf_open(struct inode *inode, struct file *file)
82{
83 return single_open(file, mic_log_buf_show, inode->i_private);
84}
85
86static int mic_log_buf_release(struct inode *inode, struct file *file)
87{
88 return single_release(inode, file);
89}
90
91static const struct file_operations log_buf_ops = {
92 .owner = THIS_MODULE,
93 .open = mic_log_buf_open,
94 .read = seq_read,
95 .llseek = seq_lseek,
96 .release = mic_log_buf_release
97};
98
99static int mic_smpt_show(struct seq_file *s, void *pos) 34static int mic_smpt_show(struct seq_file *s, void *pos)
100{ 35{
101 int i; 36 int i;
@@ -138,32 +73,6 @@ static const struct file_operations smpt_file_ops = {
138 .release = mic_smpt_debug_release 73 .release = mic_smpt_debug_release
139}; 74};
140 75
141static int mic_soft_reset_show(struct seq_file *s, void *pos)
142{
143 struct mic_device *mdev = s->private;
144
145 mic_stop(mdev, true);
146 return 0;
147}
148
149static int mic_soft_reset_debug_open(struct inode *inode, struct file *file)
150{
151 return single_open(file, mic_soft_reset_show, inode->i_private);
152}
153
154static int mic_soft_reset_debug_release(struct inode *inode, struct file *file)
155{
156 return single_release(inode, file);
157}
158
159static const struct file_operations soft_reset_ops = {
160 .owner = THIS_MODULE,
161 .open = mic_soft_reset_debug_open,
162 .read = seq_read,
163 .llseek = seq_lseek,
164 .release = mic_soft_reset_debug_release
165};
166
167static int mic_post_code_show(struct seq_file *s, void *pos) 76static int mic_post_code_show(struct seq_file *s, void *pos)
168{ 77{
169 struct mic_device *mdev = s->private; 78 struct mic_device *mdev = s->private;
@@ -204,18 +113,8 @@ static int mic_dp_show(struct seq_file *s, void *pos)
204 113
205 seq_printf(s, "Bootparam: magic 0x%x\n", 114 seq_printf(s, "Bootparam: magic 0x%x\n",
206 bootparam->magic); 115 bootparam->magic);
207 seq_printf(s, "Bootparam: h2c_shutdown_db %d\n",
208 bootparam->h2c_shutdown_db);
209 seq_printf(s, "Bootparam: h2c_config_db %d\n", 116 seq_printf(s, "Bootparam: h2c_config_db %d\n",
210 bootparam->h2c_config_db); 117 bootparam->h2c_config_db);
211 seq_printf(s, "Bootparam: c2h_shutdown_db %d\n",
212 bootparam->c2h_shutdown_db);
213 seq_printf(s, "Bootparam: shutdown_status %d\n",
214 bootparam->shutdown_status);
215 seq_printf(s, "Bootparam: shutdown_card %d\n",
216 bootparam->shutdown_card);
217 seq_printf(s, "Bootparam: tot_nodes %d\n",
218 bootparam->tot_nodes);
219 seq_printf(s, "Bootparam: node_id %d\n", 118 seq_printf(s, "Bootparam: node_id %d\n",
220 bootparam->node_id); 119 bootparam->node_id);
221 seq_printf(s, "Bootparam: c2h_scif_db %d\n", 120 seq_printf(s, "Bootparam: c2h_scif_db %d\n",
@@ -392,8 +291,7 @@ static int mic_msi_irq_info_show(struct seq_file *s, void *pos)
392 int i, j; 291 int i, j;
393 u16 entry; 292 u16 entry;
394 u16 vector; 293 u16 vector;
395 struct pci_dev *pdev = container_of(mdev->sdev->parent, 294 struct pci_dev *pdev = mdev->pdev;
396 struct pci_dev, dev);
397 295
398 if (pci_dev_msi_enabled(pdev)) { 296 if (pci_dev_msi_enabled(pdev)) {
399 for (i = 0; i < mdev->irq_info.num_vectors; i++) { 297 for (i = 0; i < mdev->irq_info.num_vectors; i++) {
@@ -454,20 +352,18 @@ static const struct file_operations msi_irq_info_ops = {
454 */ 352 */
455void mic_create_debug_dir(struct mic_device *mdev) 353void mic_create_debug_dir(struct mic_device *mdev)
456{ 354{
355 char name[16];
356
457 if (!mic_dbg) 357 if (!mic_dbg)
458 return; 358 return;
459 359
460 mdev->dbg_dir = debugfs_create_dir(dev_name(mdev->sdev), mic_dbg); 360 scnprintf(name, sizeof(name), "mic%d", mdev->id);
361 mdev->dbg_dir = debugfs_create_dir(name, mic_dbg);
461 if (!mdev->dbg_dir) 362 if (!mdev->dbg_dir)
462 return; 363 return;
463 364
464 debugfs_create_file("log_buf", 0444, mdev->dbg_dir, mdev, &log_buf_ops);
465
466 debugfs_create_file("smpt", 0444, mdev->dbg_dir, mdev, &smpt_file_ops); 365 debugfs_create_file("smpt", 0444, mdev->dbg_dir, mdev, &smpt_file_ops);
467 366
468 debugfs_create_file("soft_reset", 0444, mdev->dbg_dir, mdev,
469 &soft_reset_ops);
470
471 debugfs_create_file("post_code", 0444, mdev->dbg_dir, mdev, 367 debugfs_create_file("post_code", 0444, mdev->dbg_dir, mdev,
472 &post_code_ops); 368 &post_code_ops);
473 369
diff --git a/drivers/misc/mic/host/mic_device.h b/drivers/misc/mic/host/mic_device.h
index 01a7555aa648..461184a12fbb 100644
--- a/drivers/misc/mic/host/mic_device.h
+++ b/drivers/misc/mic/host/mic_device.h
@@ -26,21 +26,12 @@
26#include <linux/notifier.h> 26#include <linux/notifier.h>
27#include <linux/irqreturn.h> 27#include <linux/irqreturn.h>
28#include <linux/dmaengine.h> 28#include <linux/dmaengine.h>
29#include <linux/miscdevice.h>
29#include <linux/mic_bus.h> 30#include <linux/mic_bus.h>
30#include "../bus/scif_bus.h" 31#include "../bus/scif_bus.h"
32#include "../bus/cosm_bus.h"
31#include "mic_intr.h" 33#include "mic_intr.h"
32 34
33/* The maximum number of MIC devices supported in a single host system. */
34#define MIC_MAX_NUM_DEVS 256
35
36/**
37 * enum mic_hw_family - The hardware family to which a device belongs.
38 */
39enum mic_hw_family {
40 MIC_FAMILY_X100 = 0,
41 MIC_FAMILY_UNKNOWN
42};
43
44/** 35/**
45 * enum mic_stepping - MIC stepping ids. 36 * enum mic_stepping - MIC stepping ids.
46 */ 37 */
@@ -51,6 +42,8 @@ enum mic_stepping {
51 MIC_C0_STEP = 0x20, 42 MIC_C0_STEP = 0x20,
52}; 43};
53 44
45extern struct cosm_hw_ops cosm_hw_ops;
46
54/** 47/**
55 * struct mic_device - MIC device information for each card. 48 * struct mic_device - MIC device information for each card.
56 * 49 *
@@ -60,8 +53,7 @@ enum mic_stepping {
60 * @ops: MIC HW specific operations. 53 * @ops: MIC HW specific operations.
61 * @id: The unique device id for this MIC device. 54 * @id: The unique device id for this MIC device.
62 * @stepping: Stepping ID. 55 * @stepping: Stepping ID.
63 * @attr_group: Pointer to list of sysfs attribute groups. 56 * @pdev: Underlying PCI device.
64 * @sdev: Device for sysfs entries.
65 * @mic_mutex: Mutex for synchronizing access to mic_device. 57 * @mic_mutex: Mutex for synchronizing access to mic_device.
66 * @intr_ops: HW specific interrupt operations. 58 * @intr_ops: HW specific interrupt operations.
67 * @smpt_ops: Hardware specific SMPT operations. 59 * @smpt_ops: Hardware specific SMPT operations.
@@ -69,30 +61,17 @@ enum mic_stepping {
69 * @intr_info: H/W specific interrupt information. 61 * @intr_info: H/W specific interrupt information.
70 * @irq_info: The OS specific irq information 62 * @irq_info: The OS specific irq information
71 * @dbg_dir: debugfs directory of this MIC device. 63 * @dbg_dir: debugfs directory of this MIC device.
72 * @cmdline: Kernel command line.
73 * @firmware: Firmware file name.
74 * @ramdisk: Ramdisk file name.
75 * @bootmode: Boot mode i.e. "linux" or "elf" for flash updates.
76 * @bootaddr: MIC boot address. 64 * @bootaddr: MIC boot address.
77 * @reset_trigger_work: Work for triggering reset requests.
78 * @shutdown_work: Work for handling shutdown interrupts.
79 * @state: MIC state.
80 * @shutdown_status: MIC status reported by card for shutdown/crashes.
81 * @state_sysfs: Sysfs dirent for notifying ring 3 about MIC state changes.
82 * @reset_wait: Waitqueue for sleeping while reset completes.
83 * @log_buf_addr: Log buffer address for MIC.
84 * @log_buf_len: Log buffer length address for MIC.
85 * @dp: virtio device page 65 * @dp: virtio device page
86 * @dp_dma_addr: virtio device page DMA address. 66 * @dp_dma_addr: virtio device page DMA address.
87 * @shutdown_db: shutdown doorbell. 67 * @name: name for the misc char device
88 * @shutdown_cookie: shutdown cookie. 68 * @miscdev: registered misc char device
89 * @cdev: Character device for MIC.
90 * @vdev_list: list of virtio devices. 69 * @vdev_list: list of virtio devices.
91 * @pm_notifier: Handles PM notifications from the OS.
92 * @dma_mbdev: MIC BUS DMA device. 70 * @dma_mbdev: MIC BUS DMA device.
93 * @dma_ch - Array of DMA channels 71 * @dma_ch - Array of DMA channels
94 * @num_dma_ch - Number of DMA channels available 72 * @num_dma_ch - Number of DMA channels available
95 * @scdev: SCIF device on the SCIF virtual bus. 73 * @scdev: SCIF device on the SCIF virtual bus.
74 * @cosm_dev: COSM device
96 */ 75 */
97struct mic_device { 76struct mic_device {
98 struct mic_mw mmio; 77 struct mic_mw mmio;
@@ -101,8 +80,7 @@ struct mic_device {
101 struct mic_hw_ops *ops; 80 struct mic_hw_ops *ops;
102 int id; 81 int id;
103 enum mic_stepping stepping; 82 enum mic_stepping stepping;
104 const struct attribute_group **attr_group; 83 struct pci_dev *pdev;
105 struct device *sdev;
106 struct mutex mic_mutex; 84 struct mutex mic_mutex;
107 struct mic_hw_intr_ops *intr_ops; 85 struct mic_hw_intr_ops *intr_ops;
108 struct mic_smpt_ops *smpt_ops; 86 struct mic_smpt_ops *smpt_ops;
@@ -110,30 +88,17 @@ struct mic_device {
110 struct mic_intr_info *intr_info; 88 struct mic_intr_info *intr_info;
111 struct mic_irq_info irq_info; 89 struct mic_irq_info irq_info;
112 struct dentry *dbg_dir; 90 struct dentry *dbg_dir;
113 char *cmdline;
114 char *firmware;
115 char *ramdisk;
116 char *bootmode;
117 u32 bootaddr; 91 u32 bootaddr;
118 struct work_struct reset_trigger_work;
119 struct work_struct shutdown_work;
120 u8 state;
121 u8 shutdown_status;
122 struct kernfs_node *state_sysfs;
123 struct completion reset_wait;
124 void *log_buf_addr;
125 int *log_buf_len;
126 void *dp; 92 void *dp;
127 dma_addr_t dp_dma_addr; 93 dma_addr_t dp_dma_addr;
128 int shutdown_db; 94 char name[16];
129 struct mic_irq *shutdown_cookie; 95 struct miscdevice miscdev;
130 struct cdev cdev;
131 struct list_head vdev_list; 96 struct list_head vdev_list;
132 struct notifier_block pm_notifier;
133 struct mbus_device *dma_mbdev; 97 struct mbus_device *dma_mbdev;
134 struct dma_chan *dma_ch[MIC_MAX_DMA_CHAN]; 98 struct dma_chan *dma_ch[MIC_MAX_DMA_CHAN];
135 int num_dma_ch; 99 int num_dma_ch;
136 struct scif_hw_dev *scdev; 100 struct scif_hw_dev *scdev;
101 struct cosm_device *cosm_dev;
137}; 102};
138 103
139/** 104/**
@@ -199,38 +164,9 @@ mic_mmio_write(struct mic_mw *mw, u32 val, u32 offset)
199 iowrite32(val, mw->va + offset); 164 iowrite32(val, mw->va + offset);
200} 165}
201 166
202static inline struct dma_chan *mic_request_dma_chan(struct mic_device *mdev)
203{
204 dma_cap_mask_t mask;
205 struct dma_chan *chan;
206
207 dma_cap_zero(mask);
208 dma_cap_set(DMA_MEMCPY, mask);
209 chan = dma_request_channel(mask, mdev->ops->dma_filter,
210 mdev->sdev->parent);
211 if (chan)
212 return chan;
213 dev_err(mdev->sdev->parent, "%s %d unable to acquire channel\n",
214 __func__, __LINE__);
215 return NULL;
216}
217
218void mic_sysfs_init(struct mic_device *mdev);
219int mic_start(struct mic_device *mdev, const char *buf);
220void mic_stop(struct mic_device *mdev, bool force);
221void mic_shutdown(struct mic_device *mdev);
222void mic_reset_delayed_work(struct work_struct *work);
223void mic_reset_trigger_work(struct work_struct *work);
224void mic_shutdown_work(struct work_struct *work);
225void mic_bootparam_init(struct mic_device *mdev); 167void mic_bootparam_init(struct mic_device *mdev);
226void mic_set_state(struct mic_device *mdev, u8 state);
227void mic_set_shutdown_status(struct mic_device *mdev, u8 status);
228void mic_create_debug_dir(struct mic_device *dev); 168void mic_create_debug_dir(struct mic_device *dev);
229void mic_delete_debug_dir(struct mic_device *dev); 169void mic_delete_debug_dir(struct mic_device *dev);
230void __init mic_init_debugfs(void); 170void __init mic_init_debugfs(void);
231void mic_exit_debugfs(void); 171void mic_exit_debugfs(void);
232void mic_prepare_suspend(struct mic_device *mdev);
233void mic_complete_resume(struct mic_device *mdev);
234void mic_suspend(struct mic_device *mdev);
235extern atomic_t g_num_mics;
236#endif 172#endif
diff --git a/drivers/misc/mic/host/mic_fops.c b/drivers/misc/mic/host/mic_fops.c
index 85776d7327f3..8cc1d90cd949 100644
--- a/drivers/misc/mic/host/mic_fops.c
+++ b/drivers/misc/mic/host/mic_fops.c
@@ -30,8 +30,8 @@
30int mic_open(struct inode *inode, struct file *f) 30int mic_open(struct inode *inode, struct file *f)
31{ 31{
32 struct mic_vdev *mvdev; 32 struct mic_vdev *mvdev;
33 struct mic_device *mdev = container_of(inode->i_cdev, 33 struct mic_device *mdev = container_of(f->private_data,
34 struct mic_device, cdev); 34 struct mic_device, miscdev);
35 35
36 mvdev = kzalloc(sizeof(*mvdev), GFP_KERNEL); 36 mvdev = kzalloc(sizeof(*mvdev), GFP_KERNEL);
37 if (!mvdev) 37 if (!mvdev)
diff --git a/drivers/misc/mic/host/mic_intr.c b/drivers/misc/mic/host/mic_intr.c
index b4ca6c884d19..08ca3e372fa4 100644
--- a/drivers/misc/mic/host/mic_intr.c
+++ b/drivers/misc/mic/host/mic_intr.c
@@ -30,8 +30,7 @@ static irqreturn_t mic_thread_fn(int irq, void *dev)
30 struct mic_intr_info *intr_info = mdev->intr_info; 30 struct mic_intr_info *intr_info = mdev->intr_info;
31 struct mic_irq_info *irq_info = &mdev->irq_info; 31 struct mic_irq_info *irq_info = &mdev->irq_info;
32 struct mic_intr_cb *intr_cb; 32 struct mic_intr_cb *intr_cb;
33 struct pci_dev *pdev = container_of(mdev->sdev->parent, 33 struct pci_dev *pdev = mdev->pdev;
34 struct pci_dev, dev);
35 int i; 34 int i;
36 35
37 spin_lock(&irq_info->mic_thread_lock); 36 spin_lock(&irq_info->mic_thread_lock);
@@ -57,8 +56,7 @@ static irqreturn_t mic_interrupt(int irq, void *dev)
57 struct mic_intr_info *intr_info = mdev->intr_info; 56 struct mic_intr_info *intr_info = mdev->intr_info;
58 struct mic_irq_info *irq_info = &mdev->irq_info; 57 struct mic_irq_info *irq_info = &mdev->irq_info;
59 struct mic_intr_cb *intr_cb; 58 struct mic_intr_cb *intr_cb;
60 struct pci_dev *pdev = container_of(mdev->sdev->parent, 59 struct pci_dev *pdev = mdev->pdev;
61 struct pci_dev, dev);
62 u32 mask; 60 u32 mask;
63 int i; 61 int i;
64 62
@@ -83,7 +81,7 @@ static irqreturn_t mic_interrupt(int irq, void *dev)
83 81
84/* Return the interrupt offset from the index. Index is 0 based. */ 82/* Return the interrupt offset from the index. Index is 0 based. */
85static u16 mic_map_src_to_offset(struct mic_device *mdev, 83static u16 mic_map_src_to_offset(struct mic_device *mdev,
86 int intr_src, enum mic_intr_type type) 84 int intr_src, enum mic_intr_type type)
87{ 85{
88 if (type >= MIC_NUM_INTR_TYPES) 86 if (type >= MIC_NUM_INTR_TYPES)
89 return MIC_NUM_OFFSETS; 87 return MIC_NUM_OFFSETS;
@@ -214,7 +212,7 @@ static int mic_setup_msix(struct mic_device *mdev, struct pci_dev *pdev)
214 mdev->irq_info.msix_entries[i].entry = i; 212 mdev->irq_info.msix_entries[i].entry = i;
215 213
216 rc = pci_enable_msix_exact(pdev, mdev->irq_info.msix_entries, 214 rc = pci_enable_msix_exact(pdev, mdev->irq_info.msix_entries,
217 MIC_MIN_MSIX); 215 MIC_MIN_MSIX);
218 if (rc) { 216 if (rc) {
219 dev_dbg(&pdev->dev, "Error enabling MSIx. rc = %d\n", rc); 217 dev_dbg(&pdev->dev, "Error enabling MSIx. rc = %d\n", rc);
220 goto err_enable_msix; 218 goto err_enable_msix;
@@ -229,7 +227,7 @@ static int mic_setup_msix(struct mic_device *mdev, struct pci_dev *pdev)
229 goto err_nomem2; 227 goto err_nomem2;
230 } 228 }
231 229
232 dev_dbg(mdev->sdev->parent, 230 dev_dbg(&mdev->pdev->dev,
233 "%d MSIx irqs setup\n", mdev->irq_info.num_vectors); 231 "%d MSIx irqs setup\n", mdev->irq_info.num_vectors);
234 return 0; 232 return 0;
235err_nomem2: 233err_nomem2:
@@ -281,7 +279,6 @@ static void mic_release_callbacks(struct mic_device *mdev)
281 spin_lock(&mdev->irq_info.mic_thread_lock); 279 spin_lock(&mdev->irq_info.mic_thread_lock);
282 spin_lock_irqsave(&mdev->irq_info.mic_intr_lock, flags); 280 spin_lock_irqsave(&mdev->irq_info.mic_intr_lock, flags);
283 for (i = 0; i < MIC_NUM_OFFSETS; i++) { 281 for (i = 0; i < MIC_NUM_OFFSETS; i++) {
284
285 if (list_empty(&mdev->irq_info.cb_list[i])) 282 if (list_empty(&mdev->irq_info.cb_list[i]))
286 break; 283 break;
287 284
@@ -443,12 +440,11 @@ mic_request_threaded_irq(struct mic_device *mdev,
443 unsigned long cookie = 0; 440 unsigned long cookie = 0;
444 u16 entry; 441 u16 entry;
445 struct mic_intr_cb *intr_cb; 442 struct mic_intr_cb *intr_cb;
446 struct pci_dev *pdev = container_of(mdev->sdev->parent, 443 struct pci_dev *pdev = mdev->pdev;
447 struct pci_dev, dev);
448 444
449 offset = mic_map_src_to_offset(mdev, intr_src, type); 445 offset = mic_map_src_to_offset(mdev, intr_src, type);
450 if (offset >= MIC_NUM_OFFSETS) { 446 if (offset >= MIC_NUM_OFFSETS) {
451 dev_err(mdev->sdev->parent, 447 dev_err(&mdev->pdev->dev,
452 "Error mapping index %d to a valid source id.\n", 448 "Error mapping index %d to a valid source id.\n",
453 intr_src); 449 intr_src);
454 rc = -EINVAL; 450 rc = -EINVAL;
@@ -458,7 +454,7 @@ mic_request_threaded_irq(struct mic_device *mdev,
458 if (mdev->irq_info.num_vectors > 1) { 454 if (mdev->irq_info.num_vectors > 1) {
459 msix = mic_get_available_vector(mdev); 455 msix = mic_get_available_vector(mdev);
460 if (!msix) { 456 if (!msix) {
461 dev_err(mdev->sdev->parent, 457 dev_err(&mdev->pdev->dev,
462 "No MSIx vectors available for use.\n"); 458 "No MSIx vectors available for use.\n");
463 rc = -ENOSPC; 459 rc = -ENOSPC;
464 goto err; 460 goto err;
@@ -467,7 +463,7 @@ mic_request_threaded_irq(struct mic_device *mdev,
467 rc = request_threaded_irq(msix->vector, handler, thread_fn, 463 rc = request_threaded_irq(msix->vector, handler, thread_fn,
468 0, name, data); 464 0, name, data);
469 if (rc) { 465 if (rc) {
470 dev_dbg(mdev->sdev->parent, 466 dev_dbg(&mdev->pdev->dev,
471 "request irq failed rc = %d\n", rc); 467 "request irq failed rc = %d\n", rc);
472 goto err; 468 goto err;
473 } 469 }
@@ -476,13 +472,13 @@ mic_request_threaded_irq(struct mic_device *mdev,
476 mdev->intr_ops->program_msi_to_src_map(mdev, 472 mdev->intr_ops->program_msi_to_src_map(mdev,
477 entry, offset, true); 473 entry, offset, true);
478 cookie = MK_COOKIE(entry, offset); 474 cookie = MK_COOKIE(entry, offset);
479 dev_dbg(mdev->sdev->parent, "irq: %d assigned for src: %d\n", 475 dev_dbg(&mdev->pdev->dev, "irq: %d assigned for src: %d\n",
480 msix->vector, intr_src); 476 msix->vector, intr_src);
481 } else { 477 } else {
482 intr_cb = mic_register_intr_callback(mdev, offset, handler, 478 intr_cb = mic_register_intr_callback(mdev, offset, handler,
483 thread_fn, data); 479 thread_fn, data);
484 if (IS_ERR(intr_cb)) { 480 if (IS_ERR(intr_cb)) {
485 dev_err(mdev->sdev->parent, 481 dev_err(&mdev->pdev->dev,
486 "No available callback entries for use\n"); 482 "No available callback entries for use\n");
487 rc = PTR_ERR(intr_cb); 483 rc = PTR_ERR(intr_cb);
488 goto err; 484 goto err;
@@ -495,7 +491,7 @@ mic_request_threaded_irq(struct mic_device *mdev,
495 entry, offset, true); 491 entry, offset, true);
496 } 492 }
497 cookie = MK_COOKIE(entry, intr_cb->cb_id); 493 cookie = MK_COOKIE(entry, intr_cb->cb_id);
498 dev_dbg(mdev->sdev->parent, "callback %d registered for src: %d\n", 494 dev_dbg(&mdev->pdev->dev, "callback %d registered for src: %d\n",
499 intr_cb->cb_id, intr_src); 495 intr_cb->cb_id, intr_src);
500 } 496 }
501 return (struct mic_irq *)cookie; 497 return (struct mic_irq *)cookie;
@@ -515,20 +511,19 @@ err:
515 * returns: none. 511 * returns: none.
516 */ 512 */
517void mic_free_irq(struct mic_device *mdev, 513void mic_free_irq(struct mic_device *mdev,
518 struct mic_irq *cookie, void *data) 514 struct mic_irq *cookie, void *data)
519{ 515{
520 u32 offset; 516 u32 offset;
521 u32 entry; 517 u32 entry;
522 u8 src_id; 518 u8 src_id;
523 unsigned int irq; 519 unsigned int irq;
524 struct pci_dev *pdev = container_of(mdev->sdev->parent, 520 struct pci_dev *pdev = mdev->pdev;
525 struct pci_dev, dev);
526 521
527 entry = GET_ENTRY((unsigned long)cookie); 522 entry = GET_ENTRY((unsigned long)cookie);
528 offset = GET_OFFSET((unsigned long)cookie); 523 offset = GET_OFFSET((unsigned long)cookie);
529 if (mdev->irq_info.num_vectors > 1) { 524 if (mdev->irq_info.num_vectors > 1) {
530 if (entry >= mdev->irq_info.num_vectors) { 525 if (entry >= mdev->irq_info.num_vectors) {
531 dev_warn(mdev->sdev->parent, 526 dev_warn(&mdev->pdev->dev,
532 "entry %d should be < num_irq %d\n", 527 "entry %d should be < num_irq %d\n",
533 entry, mdev->irq_info.num_vectors); 528 entry, mdev->irq_info.num_vectors);
534 return; 529 return;
@@ -539,12 +534,12 @@ void mic_free_irq(struct mic_device *mdev,
539 mdev->intr_ops->program_msi_to_src_map(mdev, 534 mdev->intr_ops->program_msi_to_src_map(mdev,
540 entry, offset, false); 535 entry, offset, false);
541 536
542 dev_dbg(mdev->sdev->parent, "irq: %d freed\n", irq); 537 dev_dbg(&mdev->pdev->dev, "irq: %d freed\n", irq);
543 } else { 538 } else {
544 irq = pdev->irq; 539 irq = pdev->irq;
545 src_id = mic_unregister_intr_callback(mdev, offset); 540 src_id = mic_unregister_intr_callback(mdev, offset);
546 if (src_id >= MIC_NUM_OFFSETS) { 541 if (src_id >= MIC_NUM_OFFSETS) {
547 dev_warn(mdev->sdev->parent, "Error unregistering callback\n"); 542 dev_warn(&mdev->pdev->dev, "Error unregistering callback\n");
548 return; 543 return;
549 } 544 }
550 if (pci_dev_msi_enabled(pdev)) { 545 if (pci_dev_msi_enabled(pdev)) {
@@ -552,7 +547,7 @@ void mic_free_irq(struct mic_device *mdev,
552 mdev->intr_ops->program_msi_to_src_map(mdev, 547 mdev->intr_ops->program_msi_to_src_map(mdev,
553 entry, src_id, false); 548 entry, src_id, false);
554 } 549 }
555 dev_dbg(mdev->sdev->parent, "callback %d unregistered for src: %d\n", 550 dev_dbg(&mdev->pdev->dev, "callback %d unregistered for src: %d\n",
556 offset, src_id); 551 offset, src_id);
557 } 552 }
558} 553}
@@ -579,7 +574,7 @@ int mic_setup_interrupts(struct mic_device *mdev, struct pci_dev *pdev)
579 574
580 rc = mic_setup_intx(mdev, pdev); 575 rc = mic_setup_intx(mdev, pdev);
581 if (rc) { 576 if (rc) {
582 dev_err(mdev->sdev->parent, "no usable interrupts\n"); 577 dev_err(&mdev->pdev->dev, "no usable interrupts\n");
583 return rc; 578 return rc;
584 } 579 }
585done: 580done:
@@ -635,8 +630,7 @@ void mic_free_interrupts(struct mic_device *mdev, struct pci_dev *pdev)
635void mic_intr_restore(struct mic_device *mdev) 630void mic_intr_restore(struct mic_device *mdev)
636{ 631{
637 int entry, offset; 632 int entry, offset;
638 struct pci_dev *pdev = container_of(mdev->sdev->parent, 633 struct pci_dev *pdev = mdev->pdev;
639 struct pci_dev, dev);
640 634
641 if (!pci_dev_msi_enabled(pdev)) 635 if (!pci_dev_msi_enabled(pdev))
642 return; 636 return;
diff --git a/drivers/misc/mic/host/mic_main.c b/drivers/misc/mic/host/mic_main.c
index 456462932151..153894e7ed5b 100644
--- a/drivers/misc/mic/host/mic_main.c
+++ b/drivers/misc/mic/host/mic_main.c
@@ -16,17 +16,11 @@
16 * the file called "COPYING". 16 * the file called "COPYING".
17 * 17 *
18 * Intel MIC Host driver. 18 * Intel MIC Host driver.
19 *
20 * Global TODO's across the driver to be added after initial base
21 * patches are accepted upstream:
22 * 1) Enable DMA support.
23 * 2) Enable per vring interrupt support.
24 */ 19 */
25#include <linux/fs.h> 20#include <linux/fs.h>
26#include <linux/module.h> 21#include <linux/module.h>
27#include <linux/pci.h> 22#include <linux/pci.h>
28#include <linux/poll.h> 23#include <linux/poll.h>
29#include <linux/suspend.h>
30 24
31#include <linux/mic_common.h> 25#include <linux/mic_common.h>
32#include "../common/mic_dev.h" 26#include "../common/mic_dev.h"
@@ -63,12 +57,8 @@ MODULE_DEVICE_TABLE(pci, mic_pci_tbl);
63 57
64/* ID allocator for MIC devices */ 58/* ID allocator for MIC devices */
65static struct ida g_mic_ida; 59static struct ida g_mic_ida;
66/* Class of MIC devices for sysfs accessibility. */
67static struct class *g_mic_class;
68/* Base device node number for MIC devices */ 60/* Base device node number for MIC devices */
69static dev_t g_mic_devno; 61static dev_t g_mic_devno;
70/* Track the total number of MIC devices */
71atomic_t g_num_mics;
72 62
73static const struct file_operations mic_fops = { 63static const struct file_operations mic_fops = {
74 .open = mic_open, 64 .open = mic_open,
@@ -83,17 +73,14 @@ static const struct file_operations mic_fops = {
83static int mic_dp_init(struct mic_device *mdev) 73static int mic_dp_init(struct mic_device *mdev)
84{ 74{
85 mdev->dp = kzalloc(MIC_DP_SIZE, GFP_KERNEL); 75 mdev->dp = kzalloc(MIC_DP_SIZE, GFP_KERNEL);
86 if (!mdev->dp) { 76 if (!mdev->dp)
87 dev_err(mdev->sdev->parent, "%s %d err %d\n",
88 __func__, __LINE__, -ENOMEM);
89 return -ENOMEM; 77 return -ENOMEM;
90 }
91 78
92 mdev->dp_dma_addr = mic_map_single(mdev, 79 mdev->dp_dma_addr = mic_map_single(mdev,
93 mdev->dp, MIC_DP_SIZE); 80 mdev->dp, MIC_DP_SIZE);
94 if (mic_map_error(mdev->dp_dma_addr)) { 81 if (mic_map_error(mdev->dp_dma_addr)) {
95 kfree(mdev->dp); 82 kfree(mdev->dp);
96 dev_err(mdev->sdev->parent, "%s %d err %d\n", 83 dev_err(&mdev->pdev->dev, "%s %d err %d\n",
97 __func__, __LINE__, -ENOMEM); 84 __func__, __LINE__, -ENOMEM);
98 return -ENOMEM; 85 return -ENOMEM;
99 } 86 }
@@ -110,30 +97,6 @@ static void mic_dp_uninit(struct mic_device *mdev)
110} 97}
111 98
112/** 99/**
113 * mic_shutdown_db - Shutdown doorbell interrupt handler.
114 */
115static irqreturn_t mic_shutdown_db(int irq, void *data)
116{
117 struct mic_device *mdev = data;
118 struct mic_bootparam *bootparam = mdev->dp;
119
120 mdev->ops->intr_workarounds(mdev);
121
122 switch (bootparam->shutdown_status) {
123 case MIC_HALTED:
124 case MIC_POWER_OFF:
125 case MIC_RESTART:
126 /* Fall through */
127 case MIC_CRASHED:
128 schedule_work(&mdev->shutdown_work);
129 break;
130 default:
131 break;
132 };
133 return IRQ_HANDLED;
134}
135
136/**
137 * mic_ops_init: Initialize HW specific operation tables. 100 * mic_ops_init: Initialize HW specific operation tables.
138 * 101 *
139 * @mdev: pointer to mic_device instance 102 * @mdev: pointer to mic_device instance
@@ -190,43 +153,6 @@ static enum mic_hw_family mic_get_family(struct pci_dev *pdev)
190} 153}
191 154
192/** 155/**
193* mic_pm_notifier: Notifier callback function that handles
194* PM notifications.
195*
196* @notifier_block: The notifier structure.
197* @pm_event: The event for which the driver was notified.
198* @unused: Meaningless. Always NULL.
199*
200* returns NOTIFY_DONE
201*/
202static int mic_pm_notifier(struct notifier_block *notifier,
203 unsigned long pm_event, void *unused)
204{
205 struct mic_device *mdev = container_of(notifier,
206 struct mic_device, pm_notifier);
207
208 switch (pm_event) {
209 case PM_HIBERNATION_PREPARE:
210 /* Fall through */
211 case PM_SUSPEND_PREPARE:
212 mic_prepare_suspend(mdev);
213 break;
214 case PM_POST_HIBERNATION:
215 /* Fall through */
216 case PM_POST_SUSPEND:
217 /* Fall through */
218 case PM_POST_RESTORE:
219 mic_complete_resume(mdev);
220 break;
221 case PM_RESTORE_PREPARE:
222 break;
223 default:
224 break;
225 }
226 return NOTIFY_DONE;
227}
228
229/**
230 * mic_device_init - Allocates and initializes the MIC device structure 156 * mic_device_init - Allocates and initializes the MIC device structure
231 * 157 *
232 * @mdev: pointer to mic_device instance 158 * @mdev: pointer to mic_device instance
@@ -234,52 +160,16 @@ static int mic_pm_notifier(struct notifier_block *notifier,
234 * 160 *
235 * returns none. 161 * returns none.
236 */ 162 */
237static int 163static void
238mic_device_init(struct mic_device *mdev, struct pci_dev *pdev) 164mic_device_init(struct mic_device *mdev, struct pci_dev *pdev)
239{ 165{
240 int rc; 166 mdev->pdev = pdev;
241
242 mdev->family = mic_get_family(pdev); 167 mdev->family = mic_get_family(pdev);
243 mdev->stepping = pdev->revision; 168 mdev->stepping = pdev->revision;
244 mic_ops_init(mdev); 169 mic_ops_init(mdev);
245 mic_sysfs_init(mdev);
246 mutex_init(&mdev->mic_mutex); 170 mutex_init(&mdev->mic_mutex);
247 mdev->irq_info.next_avail_src = 0; 171 mdev->irq_info.next_avail_src = 0;
248 INIT_WORK(&mdev->reset_trigger_work, mic_reset_trigger_work);
249 INIT_WORK(&mdev->shutdown_work, mic_shutdown_work);
250 init_completion(&mdev->reset_wait);
251 INIT_LIST_HEAD(&mdev->vdev_list); 172 INIT_LIST_HEAD(&mdev->vdev_list);
252 mdev->pm_notifier.notifier_call = mic_pm_notifier;
253 rc = register_pm_notifier(&mdev->pm_notifier);
254 if (rc) {
255 dev_err(&pdev->dev, "register_pm_notifier failed rc %d\n",
256 rc);
257 goto register_pm_notifier_fail;
258 }
259 return 0;
260register_pm_notifier_fail:
261 flush_work(&mdev->shutdown_work);
262 flush_work(&mdev->reset_trigger_work);
263 return rc;
264}
265
266/**
267 * mic_device_uninit - Frees resources allocated during mic_device_init(..)
268 *
269 * @mdev: pointer to mic_device instance
270 *
271 * returns none
272 */
273static void mic_device_uninit(struct mic_device *mdev)
274{
275 /* The cmdline sysfs entry might have allocated cmdline */
276 kfree(mdev->cmdline);
277 kfree(mdev->firmware);
278 kfree(mdev->ramdisk);
279 kfree(mdev->bootmode);
280 flush_work(&mdev->reset_trigger_work);
281 flush_work(&mdev->shutdown_work);
282 unregister_pm_notifier(&mdev->pm_notifier);
283} 173}
284 174
285/** 175/**
@@ -291,7 +181,7 @@ static void mic_device_uninit(struct mic_device *mdev)
291 * returns 0 on success, < 0 on failure. 181 * returns 0 on success, < 0 on failure.
292 */ 182 */
293static int mic_probe(struct pci_dev *pdev, 183static int mic_probe(struct pci_dev *pdev,
294 const struct pci_device_id *ent) 184 const struct pci_device_id *ent)
295{ 185{
296 int rc; 186 int rc;
297 struct mic_device *mdev; 187 struct mic_device *mdev;
@@ -309,16 +199,12 @@ static int mic_probe(struct pci_dev *pdev,
309 goto ida_fail; 199 goto ida_fail;
310 } 200 }
311 201
312 rc = mic_device_init(mdev, pdev); 202 mic_device_init(mdev, pdev);
313 if (rc) {
314 dev_err(&pdev->dev, "mic_device_init failed rc %d\n", rc);
315 goto device_init_fail;
316 }
317 203
318 rc = pci_enable_device(pdev); 204 rc = pci_enable_device(pdev);
319 if (rc) { 205 if (rc) {
320 dev_err(&pdev->dev, "failed to enable pci device.\n"); 206 dev_err(&pdev->dev, "failed to enable pci device.\n");
321 goto uninit_device; 207 goto ida_remove;
322 } 208 }
323 209
324 pci_set_master(pdev); 210 pci_set_master(pdev);
@@ -367,62 +253,39 @@ static int mic_probe(struct pci_dev *pdev,
367 253
368 pci_set_drvdata(pdev, mdev); 254 pci_set_drvdata(pdev, mdev);
369 255
370 mdev->sdev = device_create_with_groups(g_mic_class, &pdev->dev,
371 MKDEV(MAJOR(g_mic_devno), mdev->id), NULL,
372 mdev->attr_group, "mic%d", mdev->id);
373 if (IS_ERR(mdev->sdev)) {
374 rc = PTR_ERR(mdev->sdev);
375 dev_err(&pdev->dev,
376 "device_create_with_groups failed rc %d\n", rc);
377 goto smpt_uninit;
378 }
379 mdev->state_sysfs = sysfs_get_dirent(mdev->sdev->kobj.sd, "state");
380 if (!mdev->state_sysfs) {
381 rc = -ENODEV;
382 dev_err(&pdev->dev, "sysfs_get_dirent failed rc %d\n", rc);
383 goto destroy_device;
384 }
385
386 rc = mic_dp_init(mdev); 256 rc = mic_dp_init(mdev);
387 if (rc) { 257 if (rc) {
388 dev_err(&pdev->dev, "mic_dp_init failed rc %d\n", rc); 258 dev_err(&pdev->dev, "mic_dp_init failed rc %d\n", rc);
389 goto sysfs_put; 259 goto smpt_uninit;
390 }
391 mutex_lock(&mdev->mic_mutex);
392
393 mdev->shutdown_db = mic_next_db(mdev);
394 mdev->shutdown_cookie = mic_request_threaded_irq(mdev, mic_shutdown_db,
395 NULL, "shutdown-interrupt", mdev,
396 mdev->shutdown_db, MIC_INTR_DB);
397 if (IS_ERR(mdev->shutdown_cookie)) {
398 rc = PTR_ERR(mdev->shutdown_cookie);
399 mutex_unlock(&mdev->mic_mutex);
400 goto dp_uninit;
401 } 260 }
402 mutex_unlock(&mdev->mic_mutex);
403 mic_bootparam_init(mdev); 261 mic_bootparam_init(mdev);
404 262
405 mic_create_debug_dir(mdev); 263 mic_create_debug_dir(mdev);
406 cdev_init(&mdev->cdev, &mic_fops); 264
407 mdev->cdev.owner = THIS_MODULE; 265 mdev->miscdev.minor = MISC_DYNAMIC_MINOR;
408 rc = cdev_add(&mdev->cdev, MKDEV(MAJOR(g_mic_devno), mdev->id), 1); 266 snprintf(mdev->name, sizeof(mdev->name), "mic%d", mdev->id);
267 mdev->miscdev.name = mdev->name;
268 mdev->miscdev.fops = &mic_fops;
269 mdev->miscdev.parent = &mdev->pdev->dev;
270 rc = misc_register(&mdev->miscdev);
409 if (rc) { 271 if (rc) {
410 dev_err(&pdev->dev, "cdev_add err id %d rc %d\n", mdev->id, rc); 272 dev_err(&pdev->dev, "misc_register err id %d rc %d\n",
273 mdev->id, rc);
411 goto cleanup_debug_dir; 274 goto cleanup_debug_dir;
412 } 275 }
413 atomic_inc(&g_num_mics); 276
277 mdev->cosm_dev = cosm_register_device(&mdev->pdev->dev, &cosm_hw_ops);
278 if (IS_ERR(mdev->cosm_dev)) {
279 rc = PTR_ERR(mdev->cosm_dev);
280 dev_err(&pdev->dev, "cosm_add_device failed rc %d\n", rc);
281 goto misc_dereg;
282 }
414 return 0; 283 return 0;
284misc_dereg:
285 misc_deregister(&mdev->miscdev);
415cleanup_debug_dir: 286cleanup_debug_dir:
416 mic_delete_debug_dir(mdev); 287 mic_delete_debug_dir(mdev);
417 mutex_lock(&mdev->mic_mutex);
418 mic_free_irq(mdev, mdev->shutdown_cookie, mdev);
419 mutex_unlock(&mdev->mic_mutex);
420dp_uninit:
421 mic_dp_uninit(mdev); 288 mic_dp_uninit(mdev);
422sysfs_put:
423 sysfs_put(mdev->state_sysfs);
424destroy_device:
425 device_destroy(g_mic_class, MKDEV(MAJOR(g_mic_devno), mdev->id));
426smpt_uninit: 289smpt_uninit:
427 mic_smpt_uninit(mdev); 290 mic_smpt_uninit(mdev);
428free_interrupts: 291free_interrupts:
@@ -435,9 +298,7 @@ release_regions:
435 pci_release_regions(pdev); 298 pci_release_regions(pdev);
436disable_device: 299disable_device:
437 pci_disable_device(pdev); 300 pci_disable_device(pdev);
438uninit_device: 301ida_remove:
439 mic_device_uninit(mdev);
440device_init_fail:
441 ida_simple_remove(&g_mic_ida, mdev->id); 302 ida_simple_remove(&g_mic_ida, mdev->id);
442ida_fail: 303ida_fail:
443 kfree(mdev); 304 kfree(mdev);
@@ -461,22 +322,14 @@ static void mic_remove(struct pci_dev *pdev)
461 if (!mdev) 322 if (!mdev)
462 return; 323 return;
463 324
464 mic_stop(mdev, false); 325 cosm_unregister_device(mdev->cosm_dev);
465 atomic_dec(&g_num_mics); 326 misc_deregister(&mdev->miscdev);
466 cdev_del(&mdev->cdev);
467 mic_delete_debug_dir(mdev); 327 mic_delete_debug_dir(mdev);
468 mutex_lock(&mdev->mic_mutex);
469 mic_free_irq(mdev, mdev->shutdown_cookie, mdev);
470 mutex_unlock(&mdev->mic_mutex);
471 flush_work(&mdev->shutdown_work);
472 mic_dp_uninit(mdev); 328 mic_dp_uninit(mdev);
473 sysfs_put(mdev->state_sysfs);
474 device_destroy(g_mic_class, MKDEV(MAJOR(g_mic_devno), mdev->id));
475 mic_smpt_uninit(mdev); 329 mic_smpt_uninit(mdev);
476 mic_free_interrupts(mdev, pdev); 330 mic_free_interrupts(mdev, pdev);
477 iounmap(mdev->mmio.va);
478 iounmap(mdev->aper.va); 331 iounmap(mdev->aper.va);
479 mic_device_uninit(mdev); 332 iounmap(mdev->mmio.va);
480 pci_release_regions(pdev); 333 pci_release_regions(pdev);
481 pci_disable_device(pdev); 334 pci_disable_device(pdev);
482 ida_simple_remove(&g_mic_ida, mdev->id); 335 ida_simple_remove(&g_mic_ida, mdev->id);
@@ -495,32 +348,23 @@ static int __init mic_init(void)
495 int ret; 348 int ret;
496 349
497 ret = alloc_chrdev_region(&g_mic_devno, 0, 350 ret = alloc_chrdev_region(&g_mic_devno, 0,
498 MIC_MAX_NUM_DEVS, mic_driver_name); 351 MIC_MAX_NUM_DEVS, mic_driver_name);
499 if (ret) { 352 if (ret) {
500 pr_err("alloc_chrdev_region failed ret %d\n", ret); 353 pr_err("alloc_chrdev_region failed ret %d\n", ret);
501 goto error; 354 goto error;
502 } 355 }
503 356
504 g_mic_class = class_create(THIS_MODULE, mic_driver_name);
505 if (IS_ERR(g_mic_class)) {
506 ret = PTR_ERR(g_mic_class);
507 pr_err("class_create failed ret %d\n", ret);
508 goto cleanup_chrdev;
509 }
510
511 mic_init_debugfs(); 357 mic_init_debugfs();
512 ida_init(&g_mic_ida); 358 ida_init(&g_mic_ida);
513 ret = pci_register_driver(&mic_driver); 359 ret = pci_register_driver(&mic_driver);
514 if (ret) { 360 if (ret) {
515 pr_err("pci_register_driver failed ret %d\n", ret); 361 pr_err("pci_register_driver failed ret %d\n", ret);
516 goto cleanup_debugfs; 362 goto cleanup_chrdev;
517 } 363 }
518 return ret; 364 return ret;
519cleanup_debugfs: 365cleanup_chrdev:
520 ida_destroy(&g_mic_ida); 366 ida_destroy(&g_mic_ida);
521 mic_exit_debugfs(); 367 mic_exit_debugfs();
522 class_destroy(g_mic_class);
523cleanup_chrdev:
524 unregister_chrdev_region(g_mic_devno, MIC_MAX_NUM_DEVS); 368 unregister_chrdev_region(g_mic_devno, MIC_MAX_NUM_DEVS);
525error: 369error:
526 return ret; 370 return ret;
@@ -531,7 +375,6 @@ static void __exit mic_exit(void)
531 pci_unregister_driver(&mic_driver); 375 pci_unregister_driver(&mic_driver);
532 ida_destroy(&g_mic_ida); 376 ida_destroy(&g_mic_ida);
533 mic_exit_debugfs(); 377 mic_exit_debugfs();
534 class_destroy(g_mic_class);
535 unregister_chrdev_region(g_mic_devno, MIC_MAX_NUM_DEVS); 378 unregister_chrdev_region(g_mic_devno, MIC_MAX_NUM_DEVS);
536} 379}
537 380
diff --git a/drivers/misc/mic/host/mic_smpt.c b/drivers/misc/mic/host/mic_smpt.c
index cec82034875f..c3f958580fb0 100644
--- a/drivers/misc/mic/host/mic_smpt.c
+++ b/drivers/misc/mic/host/mic_smpt.c
@@ -76,7 +76,7 @@ mic_is_system_addr(struct mic_device *mdev, dma_addr_t pa)
76 76
77/* Populate an SMPT entry and update the reference counts. */ 77/* Populate an SMPT entry and update the reference counts. */
78static void mic_add_smpt_entry(int spt, s64 *ref, u64 addr, 78static void mic_add_smpt_entry(int spt, s64 *ref, u64 addr,
79 int entries, struct mic_device *mdev) 79 int entries, struct mic_device *mdev)
80{ 80{
81 struct mic_smpt_info *smpt_info = mdev->smpt; 81 struct mic_smpt_info *smpt_info = mdev->smpt;
82 int i; 82 int i;
@@ -97,7 +97,7 @@ static void mic_add_smpt_entry(int spt, s64 *ref, u64 addr,
97 * for a given DMA address and size. 97 * for a given DMA address and size.
98 */ 98 */
99static dma_addr_t mic_smpt_op(struct mic_device *mdev, u64 dma_addr, 99static dma_addr_t mic_smpt_op(struct mic_device *mdev, u64 dma_addr,
100 int entries, s64 *ref, size_t size) 100 int entries, s64 *ref, size_t size)
101{ 101{
102 int spt; 102 int spt;
103 int ae = 0; 103 int ae = 0;
@@ -148,7 +148,7 @@ found:
148 * and the starting smpt address 148 * and the starting smpt address
149 */ 149 */
150static int mic_get_smpt_ref_count(struct mic_device *mdev, dma_addr_t dma_addr, 150static int mic_get_smpt_ref_count(struct mic_device *mdev, dma_addr_t dma_addr,
151 size_t size, s64 *ref, u64 *smpt_start) 151 size_t size, s64 *ref, u64 *smpt_start)
152{ 152{
153 u64 start = dma_addr; 153 u64 start = dma_addr;
154 u64 end = dma_addr + size; 154 u64 end = dma_addr + size;
@@ -181,7 +181,7 @@ dma_addr_t mic_to_dma_addr(struct mic_device *mdev, dma_addr_t mic_addr)
181 dma_addr_t dma_addr; 181 dma_addr_t dma_addr;
182 182
183 if (!mic_is_system_addr(mdev, mic_addr)) { 183 if (!mic_is_system_addr(mdev, mic_addr)) {
184 dev_err(mdev->sdev->parent, 184 dev_err(&mdev->pdev->dev,
185 "mic_addr is invalid. mic_addr = 0x%llx\n", mic_addr); 185 "mic_addr is invalid. mic_addr = 0x%llx\n", mic_addr);
186 return -EINVAL; 186 return -EINVAL;
187 } 187 }
@@ -218,7 +218,7 @@ dma_addr_t mic_map(struct mic_device *mdev, dma_addr_t dma_addr, size_t size)
218 return mic_addr; 218 return mic_addr;
219 219
220 num_entries = mic_get_smpt_ref_count(mdev, dma_addr, size, 220 num_entries = mic_get_smpt_ref_count(mdev, dma_addr, size,
221 ref, &smpt_start); 221 ref, &smpt_start);
222 222
223 /* Set the smpt table appropriately and get 16G aligned mic address */ 223 /* Set the smpt table appropriately and get 16G aligned mic address */
224 mic_addr = mic_smpt_op(mdev, smpt_start, num_entries, ref, size); 224 mic_addr = mic_smpt_op(mdev, smpt_start, num_entries, ref, size);
@@ -231,7 +231,7 @@ dma_addr_t mic_map(struct mic_device *mdev, dma_addr_t dma_addr, size_t size)
231 * else generate mic_addr by adding the 16G offset in dma_addr 231 * else generate mic_addr by adding the 16G offset in dma_addr
232 */ 232 */
233 if (!mic_addr && MIC_FAMILY_X100 == mdev->family) { 233 if (!mic_addr && MIC_FAMILY_X100 == mdev->family) {
234 dev_err(mdev->sdev->parent, 234 dev_err(&mdev->pdev->dev,
235 "mic_map failed dma_addr 0x%llx size 0x%lx\n", 235 "mic_map failed dma_addr 0x%llx size 0x%lx\n",
236 dma_addr, size); 236 dma_addr, size);
237 return mic_addr; 237 return mic_addr;
@@ -264,7 +264,7 @@ void mic_unmap(struct mic_device *mdev, dma_addr_t mic_addr, size_t size)
264 return; 264 return;
265 265
266 if (!mic_is_system_addr(mdev, mic_addr)) { 266 if (!mic_is_system_addr(mdev, mic_addr)) {
267 dev_err(mdev->sdev->parent, 267 dev_err(&mdev->pdev->dev,
268 "invalid address: 0x%llx\n", mic_addr); 268 "invalid address: 0x%llx\n", mic_addr);
269 return; 269 return;
270 } 270 }
@@ -284,7 +284,7 @@ void mic_unmap(struct mic_device *mdev, dma_addr_t mic_addr, size_t size)
284 for (i = spt; i < spt + num_smpt; i++) { 284 for (i = spt; i < spt + num_smpt; i++) {
285 smpt_info->entry[i].ref_count -= ref[i - spt]; 285 smpt_info->entry[i].ref_count -= ref[i - spt];
286 if (smpt_info->entry[i].ref_count < 0) 286 if (smpt_info->entry[i].ref_count < 0)
287 dev_warn(mdev->sdev->parent, 287 dev_warn(&mdev->pdev->dev,
288 "ref count for entry %d is negative\n", i); 288 "ref count for entry %d is negative\n", i);
289 } 289 }
290 spin_unlock_irqrestore(&smpt_info->smpt_lock, flags); 290 spin_unlock_irqrestore(&smpt_info->smpt_lock, flags);
@@ -307,15 +307,14 @@ void mic_unmap(struct mic_device *mdev, dma_addr_t mic_addr, size_t size)
307dma_addr_t mic_map_single(struct mic_device *mdev, void *va, size_t size) 307dma_addr_t mic_map_single(struct mic_device *mdev, void *va, size_t size)
308{ 308{
309 dma_addr_t mic_addr = 0; 309 dma_addr_t mic_addr = 0;
310 struct pci_dev *pdev = container_of(mdev->sdev->parent, 310 struct pci_dev *pdev = mdev->pdev;
311 struct pci_dev, dev);
312 dma_addr_t dma_addr = 311 dma_addr_t dma_addr =
313 pci_map_single(pdev, va, size, PCI_DMA_BIDIRECTIONAL); 312 pci_map_single(pdev, va, size, PCI_DMA_BIDIRECTIONAL);
314 313
315 if (!pci_dma_mapping_error(pdev, dma_addr)) { 314 if (!pci_dma_mapping_error(pdev, dma_addr)) {
316 mic_addr = mic_map(mdev, dma_addr, size); 315 mic_addr = mic_map(mdev, dma_addr, size);
317 if (!mic_addr) { 316 if (!mic_addr) {
318 dev_err(mdev->sdev->parent, 317 dev_err(&mdev->pdev->dev,
319 "mic_map failed dma_addr 0x%llx size 0x%lx\n", 318 "mic_map failed dma_addr 0x%llx size 0x%lx\n",
320 dma_addr, size); 319 dma_addr, size);
321 pci_unmap_single(pdev, dma_addr, 320 pci_unmap_single(pdev, dma_addr,
@@ -339,8 +338,7 @@ dma_addr_t mic_map_single(struct mic_device *mdev, void *va, size_t size)
339void 338void
340mic_unmap_single(struct mic_device *mdev, dma_addr_t mic_addr, size_t size) 339mic_unmap_single(struct mic_device *mdev, dma_addr_t mic_addr, size_t size)
341{ 340{
342 struct pci_dev *pdev = container_of(mdev->sdev->parent, 341 struct pci_dev *pdev = mdev->pdev;
343 struct pci_dev, dev);
344 dma_addr_t dma_addr = mic_to_dma_addr(mdev, mic_addr); 342 dma_addr_t dma_addr = mic_to_dma_addr(mdev, mic_addr);
345 mic_unmap(mdev, mic_addr, size); 343 mic_unmap(mdev, mic_addr, size);
346 pci_unmap_single(pdev, dma_addr, size, PCI_DMA_BIDIRECTIONAL); 344 pci_unmap_single(pdev, dma_addr, size, PCI_DMA_BIDIRECTIONAL);
@@ -399,18 +397,18 @@ void mic_smpt_uninit(struct mic_device *mdev)
399 struct mic_smpt_info *smpt_info = mdev->smpt; 397 struct mic_smpt_info *smpt_info = mdev->smpt;
400 int i; 398 int i;
401 399
402 dev_dbg(mdev->sdev->parent, 400 dev_dbg(&mdev->pdev->dev,
403 "nodeid %d SMPT ref count %lld map %lld unmap %lld\n", 401 "nodeid %d SMPT ref count %lld map %lld unmap %lld\n",
404 mdev->id, smpt_info->ref_count, 402 mdev->id, smpt_info->ref_count,
405 smpt_info->map_count, smpt_info->unmap_count); 403 smpt_info->map_count, smpt_info->unmap_count);
406 404
407 for (i = 0; i < smpt_info->info.num_reg; i++) { 405 for (i = 0; i < smpt_info->info.num_reg; i++) {
408 dev_dbg(mdev->sdev->parent, 406 dev_dbg(&mdev->pdev->dev,
409 "SMPT entry[%d] dma_addr = 0x%llx ref_count = %lld\n", 407 "SMPT entry[%d] dma_addr = 0x%llx ref_count = %lld\n",
410 i, smpt_info->entry[i].dma_addr, 408 i, smpt_info->entry[i].dma_addr,
411 smpt_info->entry[i].ref_count); 409 smpt_info->entry[i].ref_count);
412 if (smpt_info->entry[i].ref_count) 410 if (smpt_info->entry[i].ref_count)
413 dev_warn(mdev->sdev->parent, 411 dev_warn(&mdev->pdev->dev,
414 "ref count for entry %d is not zero\n", i); 412 "ref count for entry %d is not zero\n", i);
415 } 413 }
416 kfree(smpt_info->entry); 414 kfree(smpt_info->entry);
diff --git a/drivers/misc/mic/host/mic_sysfs.c b/drivers/misc/mic/host/mic_sysfs.c
deleted file mode 100644
index 6dd864e4a617..000000000000
--- a/drivers/misc/mic/host/mic_sysfs.c
+++ /dev/null
@@ -1,459 +0,0 @@
1/*
2 * Intel MIC Platform Software Stack (MPSS)
3 *
4 * Copyright(c) 2013 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
17 *
18 * Intel MIC Host driver.
19 *
20 */
21#include <linux/pci.h>
22
23#include <linux/mic_common.h>
24#include "../common/mic_dev.h"
25#include "mic_device.h"
26
27/*
28 * A state-to-string lookup table, for exposing a human readable state
29 * via sysfs. Always keep in sync with enum mic_states
30 */
31static const char * const mic_state_string[] = {
32 [MIC_OFFLINE] = "offline",
33 [MIC_ONLINE] = "online",
34 [MIC_SHUTTING_DOWN] = "shutting_down",
35 [MIC_RESET_FAILED] = "reset_failed",
36 [MIC_SUSPENDING] = "suspending",
37 [MIC_SUSPENDED] = "suspended",
38};
39
40/*
41 * A shutdown-status-to-string lookup table, for exposing a human
42 * readable state via sysfs. Always keep in sync with enum mic_shutdown_status
43 */
44static const char * const mic_shutdown_status_string[] = {
45 [MIC_NOP] = "nop",
46 [MIC_CRASHED] = "crashed",
47 [MIC_HALTED] = "halted",
48 [MIC_POWER_OFF] = "poweroff",
49 [MIC_RESTART] = "restart",
50};
51
52void mic_set_shutdown_status(struct mic_device *mdev, u8 shutdown_status)
53{
54 dev_dbg(mdev->sdev->parent, "Shutdown Status %s -> %s\n",
55 mic_shutdown_status_string[mdev->shutdown_status],
56 mic_shutdown_status_string[shutdown_status]);
57 mdev->shutdown_status = shutdown_status;
58}
59
60void mic_set_state(struct mic_device *mdev, u8 state)
61{
62 dev_dbg(mdev->sdev->parent, "State %s -> %s\n",
63 mic_state_string[mdev->state],
64 mic_state_string[state]);
65 mdev->state = state;
66 sysfs_notify_dirent(mdev->state_sysfs);
67}
68
69static ssize_t
70family_show(struct device *dev, struct device_attribute *attr, char *buf)
71{
72 static const char x100[] = "x100";
73 static const char unknown[] = "Unknown";
74 const char *card = NULL;
75 struct mic_device *mdev = dev_get_drvdata(dev->parent);
76
77 if (!mdev)
78 return -EINVAL;
79
80 switch (mdev->family) {
81 case MIC_FAMILY_X100:
82 card = x100;
83 break;
84 default:
85 card = unknown;
86 break;
87 }
88 return scnprintf(buf, PAGE_SIZE, "%s\n", card);
89}
90static DEVICE_ATTR_RO(family);
91
92static ssize_t
93stepping_show(struct device *dev, struct device_attribute *attr, char *buf)
94{
95 struct mic_device *mdev = dev_get_drvdata(dev->parent);
96 char *string = "??";
97
98 if (!mdev)
99 return -EINVAL;
100
101 switch (mdev->stepping) {
102 case MIC_A0_STEP:
103 string = "A0";
104 break;
105 case MIC_B0_STEP:
106 string = "B0";
107 break;
108 case MIC_B1_STEP:
109 string = "B1";
110 break;
111 case MIC_C0_STEP:
112 string = "C0";
113 break;
114 default:
115 break;
116 }
117 return scnprintf(buf, PAGE_SIZE, "%s\n", string);
118}
119static DEVICE_ATTR_RO(stepping);
120
121static ssize_t
122state_show(struct device *dev, struct device_attribute *attr, char *buf)
123{
124 struct mic_device *mdev = dev_get_drvdata(dev->parent);
125
126 if (!mdev || mdev->state >= MIC_LAST)
127 return -EINVAL;
128
129 return scnprintf(buf, PAGE_SIZE, "%s\n",
130 mic_state_string[mdev->state]);
131}
132
133static ssize_t
134state_store(struct device *dev, struct device_attribute *attr,
135 const char *buf, size_t count)
136{
137 int rc = 0;
138 struct mic_device *mdev = dev_get_drvdata(dev->parent);
139 if (!mdev)
140 return -EINVAL;
141 if (sysfs_streq(buf, "boot")) {
142 rc = mic_start(mdev, buf);
143 if (rc) {
144 dev_err(mdev->sdev->parent,
145 "mic_boot failed rc %d\n", rc);
146 count = rc;
147 }
148 goto done;
149 }
150
151 if (sysfs_streq(buf, "reset")) {
152 schedule_work(&mdev->reset_trigger_work);
153 goto done;
154 }
155
156 if (sysfs_streq(buf, "shutdown")) {
157 mic_shutdown(mdev);
158 goto done;
159 }
160
161 if (sysfs_streq(buf, "suspend")) {
162 mic_suspend(mdev);
163 goto done;
164 }
165
166 count = -EINVAL;
167done:
168 return count;
169}
170static DEVICE_ATTR_RW(state);
171
172static ssize_t shutdown_status_show(struct device *dev,
173 struct device_attribute *attr, char *buf)
174{
175 struct mic_device *mdev = dev_get_drvdata(dev->parent);
176
177 if (!mdev || mdev->shutdown_status >= MIC_STATUS_LAST)
178 return -EINVAL;
179
180 return scnprintf(buf, PAGE_SIZE, "%s\n",
181 mic_shutdown_status_string[mdev->shutdown_status]);
182}
183static DEVICE_ATTR_RO(shutdown_status);
184
185static ssize_t
186cmdline_show(struct device *dev, struct device_attribute *attr, char *buf)
187{
188 struct mic_device *mdev = dev_get_drvdata(dev->parent);
189 char *cmdline;
190
191 if (!mdev)
192 return -EINVAL;
193
194 cmdline = mdev->cmdline;
195
196 if (cmdline)
197 return scnprintf(buf, PAGE_SIZE, "%s\n", cmdline);
198 return 0;
199}
200
201static ssize_t
202cmdline_store(struct device *dev, struct device_attribute *attr,
203 const char *buf, size_t count)
204{
205 struct mic_device *mdev = dev_get_drvdata(dev->parent);
206
207 if (!mdev)
208 return -EINVAL;
209
210 mutex_lock(&mdev->mic_mutex);
211 kfree(mdev->cmdline);
212
213 mdev->cmdline = kmalloc(count + 1, GFP_KERNEL);
214 if (!mdev->cmdline) {
215 count = -ENOMEM;
216 goto unlock;
217 }
218
219 strncpy(mdev->cmdline, buf, count);
220
221 if (mdev->cmdline[count - 1] == '\n')
222 mdev->cmdline[count - 1] = '\0';
223 else
224 mdev->cmdline[count] = '\0';
225unlock:
226 mutex_unlock(&mdev->mic_mutex);
227 return count;
228}
229static DEVICE_ATTR_RW(cmdline);
230
231static ssize_t
232firmware_show(struct device *dev, struct device_attribute *attr, char *buf)
233{
234 struct mic_device *mdev = dev_get_drvdata(dev->parent);
235 char *firmware;
236
237 if (!mdev)
238 return -EINVAL;
239
240 firmware = mdev->firmware;
241
242 if (firmware)
243 return scnprintf(buf, PAGE_SIZE, "%s\n", firmware);
244 return 0;
245}
246
247static ssize_t
248firmware_store(struct device *dev, struct device_attribute *attr,
249 const char *buf, size_t count)
250{
251 struct mic_device *mdev = dev_get_drvdata(dev->parent);
252
253 if (!mdev)
254 return -EINVAL;
255
256 mutex_lock(&mdev->mic_mutex);
257 kfree(mdev->firmware);
258
259 mdev->firmware = kmalloc(count + 1, GFP_KERNEL);
260 if (!mdev->firmware) {
261 count = -ENOMEM;
262 goto unlock;
263 }
264 strncpy(mdev->firmware, buf, count);
265
266 if (mdev->firmware[count - 1] == '\n')
267 mdev->firmware[count - 1] = '\0';
268 else
269 mdev->firmware[count] = '\0';
270unlock:
271 mutex_unlock(&mdev->mic_mutex);
272 return count;
273}
274static DEVICE_ATTR_RW(firmware);
275
276static ssize_t
277ramdisk_show(struct device *dev, struct device_attribute *attr, char *buf)
278{
279 struct mic_device *mdev = dev_get_drvdata(dev->parent);
280 char *ramdisk;
281
282 if (!mdev)
283 return -EINVAL;
284
285 ramdisk = mdev->ramdisk;
286
287 if (ramdisk)
288 return scnprintf(buf, PAGE_SIZE, "%s\n", ramdisk);
289 return 0;
290}
291
292static ssize_t
293ramdisk_store(struct device *dev, struct device_attribute *attr,
294 const char *buf, size_t count)
295{
296 struct mic_device *mdev = dev_get_drvdata(dev->parent);
297
298 if (!mdev)
299 return -EINVAL;
300
301 mutex_lock(&mdev->mic_mutex);
302 kfree(mdev->ramdisk);
303
304 mdev->ramdisk = kmalloc(count + 1, GFP_KERNEL);
305 if (!mdev->ramdisk) {
306 count = -ENOMEM;
307 goto unlock;
308 }
309
310 strncpy(mdev->ramdisk, buf, count);
311
312 if (mdev->ramdisk[count - 1] == '\n')
313 mdev->ramdisk[count - 1] = '\0';
314 else
315 mdev->ramdisk[count] = '\0';
316unlock:
317 mutex_unlock(&mdev->mic_mutex);
318 return count;
319}
320static DEVICE_ATTR_RW(ramdisk);
321
322static ssize_t
323bootmode_show(struct device *dev, struct device_attribute *attr, char *buf)
324{
325 struct mic_device *mdev = dev_get_drvdata(dev->parent);
326 char *bootmode;
327
328 if (!mdev)
329 return -EINVAL;
330
331 bootmode = mdev->bootmode;
332
333 if (bootmode)
334 return scnprintf(buf, PAGE_SIZE, "%s\n", bootmode);
335 return 0;
336}
337
338static ssize_t
339bootmode_store(struct device *dev, struct device_attribute *attr,
340 const char *buf, size_t count)
341{
342 struct mic_device *mdev = dev_get_drvdata(dev->parent);
343
344 if (!mdev)
345 return -EINVAL;
346
347 if (!sysfs_streq(buf, "linux") && !sysfs_streq(buf, "elf"))
348 return -EINVAL;
349
350 mutex_lock(&mdev->mic_mutex);
351 kfree(mdev->bootmode);
352
353 mdev->bootmode = kmalloc(count + 1, GFP_KERNEL);
354 if (!mdev->bootmode) {
355 count = -ENOMEM;
356 goto unlock;
357 }
358
359 strncpy(mdev->bootmode, buf, count);
360
361 if (mdev->bootmode[count - 1] == '\n')
362 mdev->bootmode[count - 1] = '\0';
363 else
364 mdev->bootmode[count] = '\0';
365unlock:
366 mutex_unlock(&mdev->mic_mutex);
367 return count;
368}
369static DEVICE_ATTR_RW(bootmode);
370
371static ssize_t
372log_buf_addr_show(struct device *dev, struct device_attribute *attr,
373 char *buf)
374{
375 struct mic_device *mdev = dev_get_drvdata(dev->parent);
376
377 if (!mdev)
378 return -EINVAL;
379
380 return scnprintf(buf, PAGE_SIZE, "%p\n", mdev->log_buf_addr);
381}
382
383static ssize_t
384log_buf_addr_store(struct device *dev, struct device_attribute *attr,
385 const char *buf, size_t count)
386{
387 struct mic_device *mdev = dev_get_drvdata(dev->parent);
388 int ret;
389 unsigned long addr;
390
391 if (!mdev)
392 return -EINVAL;
393
394 ret = kstrtoul(buf, 16, &addr);
395 if (ret)
396 goto exit;
397
398 mdev->log_buf_addr = (void *)addr;
399 ret = count;
400exit:
401 return ret;
402}
403static DEVICE_ATTR_RW(log_buf_addr);
404
405static ssize_t
406log_buf_len_show(struct device *dev, struct device_attribute *attr,
407 char *buf)
408{
409 struct mic_device *mdev = dev_get_drvdata(dev->parent);
410
411 if (!mdev)
412 return -EINVAL;
413
414 return scnprintf(buf, PAGE_SIZE, "%p\n", mdev->log_buf_len);
415}
416
417static ssize_t
418log_buf_len_store(struct device *dev, struct device_attribute *attr,
419 const char *buf, size_t count)
420{
421 struct mic_device *mdev = dev_get_drvdata(dev->parent);
422 int ret;
423 unsigned long addr;
424
425 if (!mdev)
426 return -EINVAL;
427
428 ret = kstrtoul(buf, 16, &addr);
429 if (ret)
430 goto exit;
431
432 mdev->log_buf_len = (int *)addr;
433 ret = count;
434exit:
435 return ret;
436}
437static DEVICE_ATTR_RW(log_buf_len);
438
439static struct attribute *mic_default_attrs[] = {
440 &dev_attr_family.attr,
441 &dev_attr_stepping.attr,
442 &dev_attr_state.attr,
443 &dev_attr_shutdown_status.attr,
444 &dev_attr_cmdline.attr,
445 &dev_attr_firmware.attr,
446 &dev_attr_ramdisk.attr,
447 &dev_attr_bootmode.attr,
448 &dev_attr_log_buf_addr.attr,
449 &dev_attr_log_buf_len.attr,
450
451 NULL
452};
453
454ATTRIBUTE_GROUPS(mic_default);
455
456void mic_sysfs_init(struct mic_device *mdev)
457{
458 mdev->attr_group = mic_default_groups;
459}
diff --git a/drivers/misc/mic/host/mic_virtio.c b/drivers/misc/mic/host/mic_virtio.c
index cc08e9f733c9..58b107a24a8b 100644
--- a/drivers/misc/mic/host/mic_virtio.c
+++ b/drivers/misc/mic/host/mic_virtio.c
@@ -23,7 +23,6 @@
23#include <linux/uaccess.h> 23#include <linux/uaccess.h>
24#include <linux/dmaengine.h> 24#include <linux/dmaengine.h>
25#include <linux/mic_common.h> 25#include <linux/mic_common.h>
26
27#include "../common/mic_dev.h" 26#include "../common/mic_dev.h"
28#include "mic_device.h" 27#include "mic_device.h"
29#include "mic_smpt.h" 28#include "mic_smpt.h"
@@ -62,7 +61,7 @@ static int mic_sync_dma(struct mic_device *mdev, dma_addr_t dst,
62 } 61 }
63error: 62error:
64 if (err) 63 if (err)
65 dev_err(mdev->sdev->parent, "%s %d err %d\n", 64 dev_err(&mdev->pdev->dev, "%s %d err %d\n",
66 __func__, __LINE__, err); 65 __func__, __LINE__, err);
67 return err; 66 return err;
68} 67}
@@ -440,7 +439,7 @@ void mic_virtio_reset_devices(struct mic_device *mdev)
440 struct list_head *pos, *tmp; 439 struct list_head *pos, *tmp;
441 struct mic_vdev *mvdev; 440 struct mic_vdev *mvdev;
442 441
443 dev_dbg(mdev->sdev->parent, "%s\n", __func__); 442 dev_dbg(&mdev->pdev->dev, "%s\n", __func__);
444 443
445 list_for_each_safe(pos, tmp, &mdev->vdev_list) { 444 list_for_each_safe(pos, tmp, &mdev->vdev_list) {
446 mvdev = list_entry(pos, struct mic_vdev, list); 445 mvdev = list_entry(pos, struct mic_vdev, list);
@@ -686,7 +685,7 @@ int mic_virtio_add_device(struct mic_vdev *mvdev,
686 mvr->head = USHRT_MAX; 685 mvr->head = USHRT_MAX;
687 mvr->mvdev = mvdev; 686 mvr->mvdev = mvdev;
688 mvr->vrh.notify = mic_notify; 687 mvr->vrh.notify = mic_notify;
689 dev_dbg(mdev->sdev->parent, 688 dev_dbg(&mdev->pdev->dev,
690 "%s %d index %d va %p info %p vr_size 0x%x\n", 689 "%s %d index %d va %p info %p vr_size 0x%x\n",
691 __func__, __LINE__, i, vr->va, vr->info, vr_size); 690 __func__, __LINE__, i, vr->va, vr->info, vr_size);
692 mvr->buf = (void *)__get_free_pages(GFP_KERNEL, 691 mvr->buf = (void *)__get_free_pages(GFP_KERNEL,
@@ -704,7 +703,7 @@ int mic_virtio_add_device(struct mic_vdev *mvdev,
704 mvdev->virtio_db, MIC_INTR_DB); 703 mvdev->virtio_db, MIC_INTR_DB);
705 if (IS_ERR(mvdev->virtio_cookie)) { 704 if (IS_ERR(mvdev->virtio_cookie)) {
706 ret = PTR_ERR(mvdev->virtio_cookie); 705 ret = PTR_ERR(mvdev->virtio_cookie);
707 dev_dbg(mdev->sdev->parent, "request irq failed\n"); 706 dev_dbg(&mdev->pdev->dev, "request irq failed\n");
708 goto err; 707 goto err;
709 } 708 }
710 709
@@ -720,7 +719,7 @@ int mic_virtio_add_device(struct mic_vdev *mvdev,
720 smp_wmb(); 719 smp_wmb();
721 dd->type = type; 720 dd->type = type;
722 721
723 dev_dbg(mdev->sdev->parent, "Added virtio device id %d\n", dd->type); 722 dev_dbg(&mdev->pdev->dev, "Added virtio device id %d\n", dd->type);
724 723
725 db = bootparam->h2c_config_db; 724 db = bootparam->h2c_config_db;
726 if (db != -1) 725 if (db != -1)
@@ -755,7 +754,7 @@ void mic_virtio_del_device(struct mic_vdev *mvdev)
755 db = bootparam->h2c_config_db; 754 db = bootparam->h2c_config_db;
756 if (db == -1) 755 if (db == -1)
757 goto skip_hot_remove; 756 goto skip_hot_remove;
758 dev_dbg(mdev->sdev->parent, 757 dev_dbg(&mdev->pdev->dev,
759 "Requesting hot remove id %d\n", mvdev->virtio_id); 758 "Requesting hot remove id %d\n", mvdev->virtio_id);
760 mvdev->dc->config_change = MIC_VIRTIO_PARAM_DEV_REMOVE; 759 mvdev->dc->config_change = MIC_VIRTIO_PARAM_DEV_REMOVE;
761 mdev->ops->send_intr(mdev, db); 760 mdev->ops->send_intr(mdev, db);
@@ -765,7 +764,7 @@ void mic_virtio_del_device(struct mic_vdev *mvdev)
765 if (ret) 764 if (ret)
766 break; 765 break;
767 } 766 }
768 dev_dbg(mdev->sdev->parent, 767 dev_dbg(&mdev->pdev->dev,
769 "Device id %d config_change %d guest_ack %d retry %d\n", 768 "Device id %d config_change %d guest_ack %d retry %d\n",
770 mvdev->virtio_id, mvdev->dc->config_change, 769 mvdev->virtio_id, mvdev->dc->config_change,
771 mvdev->dc->guest_ack, retry); 770 mvdev->dc->guest_ack, retry);
@@ -794,7 +793,7 @@ skip_hot_remove:
794 tmp_mvdev = list_entry(pos, struct mic_vdev, list); 793 tmp_mvdev = list_entry(pos, struct mic_vdev, list);
795 if (tmp_mvdev == mvdev) { 794 if (tmp_mvdev == mvdev) {
796 list_del(pos); 795 list_del(pos);
797 dev_dbg(mdev->sdev->parent, 796 dev_dbg(&mdev->pdev->dev,
798 "Removing virtio device id %d\n", 797 "Removing virtio device id %d\n",
799 mvdev->virtio_id); 798 mvdev->virtio_id);
800 break; 799 break;
diff --git a/drivers/misc/mic/host/mic_virtio.h b/drivers/misc/mic/host/mic_virtio.h
index d574efb853d9..a80631f2790d 100644
--- a/drivers/misc/mic/host/mic_virtio.h
+++ b/drivers/misc/mic/host/mic_virtio.h
@@ -124,7 +124,7 @@ void mic_bh_handler(struct work_struct *work);
124/* Helper API to obtain the MIC PCIe device */ 124/* Helper API to obtain the MIC PCIe device */
125static inline struct device *mic_dev(struct mic_vdev *mvdev) 125static inline struct device *mic_dev(struct mic_vdev *mvdev)
126{ 126{
127 return mvdev->mdev->sdev->parent; 127 return &mvdev->mdev->pdev->dev;
128} 128}
129 129
130/* Helper API to check if a virtio device is initialized */ 130/* Helper API to check if a virtio device is initialized */
diff --git a/drivers/misc/mic/host/mic_x100.c b/drivers/misc/mic/host/mic_x100.c
index 3341e90dede4..8118ac48c764 100644
--- a/drivers/misc/mic/host/mic_x100.c
+++ b/drivers/misc/mic/host/mic_x100.c
@@ -43,7 +43,7 @@
43static void 43static void
44mic_x100_write_spad(struct mic_device *mdev, unsigned int idx, u32 val) 44mic_x100_write_spad(struct mic_device *mdev, unsigned int idx, u32 val)
45{ 45{
46 dev_dbg(mdev->sdev->parent, "Writing 0x%x to scratch pad index %d\n", 46 dev_dbg(&mdev->pdev->dev, "Writing 0x%x to scratch pad index %d\n",
47 val, idx); 47 val, idx);
48 mic_mmio_write(&mdev->mmio, val, 48 mic_mmio_write(&mdev->mmio, val,
49 MIC_X100_SBOX_BASE_ADDRESS + 49 MIC_X100_SBOX_BASE_ADDRESS +
@@ -66,7 +66,7 @@ mic_x100_read_spad(struct mic_device *mdev, unsigned int idx)
66 MIC_X100_SBOX_BASE_ADDRESS + 66 MIC_X100_SBOX_BASE_ADDRESS +
67 MIC_X100_SBOX_SPAD0 + idx * 4); 67 MIC_X100_SBOX_SPAD0 + idx * 4);
68 68
69 dev_dbg(mdev->sdev->parent, 69 dev_dbg(&mdev->pdev->dev,
70 "Reading 0x%x from scratch pad index %d\n", val, idx); 70 "Reading 0x%x from scratch pad index %d\n", val, idx);
71 return val; 71 return val;
72} 72}
@@ -126,7 +126,7 @@ static void mic_x100_disable_interrupts(struct mic_device *mdev)
126 * @mdev: pointer to mic_device instance 126 * @mdev: pointer to mic_device instance
127 */ 127 */
128static void mic_x100_send_sbox_intr(struct mic_device *mdev, 128static void mic_x100_send_sbox_intr(struct mic_device *mdev,
129 int doorbell) 129 int doorbell)
130{ 130{
131 struct mic_mw *mw = &mdev->mmio; 131 struct mic_mw *mw = &mdev->mmio;
132 u64 apic_icr_offset = MIC_X100_SBOX_APICICR0 + doorbell * 8; 132 u64 apic_icr_offset = MIC_X100_SBOX_APICICR0 + doorbell * 8;
@@ -147,7 +147,7 @@ static void mic_x100_send_sbox_intr(struct mic_device *mdev,
147 * @mdev: pointer to mic_device instance 147 * @mdev: pointer to mic_device instance
148 */ 148 */
149static void mic_x100_send_rdmasr_intr(struct mic_device *mdev, 149static void mic_x100_send_rdmasr_intr(struct mic_device *mdev,
150 int doorbell) 150 int doorbell)
151{ 151{
152 int rdmasr_offset = MIC_X100_SBOX_RDMASR0 + (doorbell << 2); 152 int rdmasr_offset = MIC_X100_SBOX_RDMASR0 + (doorbell << 2);
153 /* Ensure that the interrupt is ordered w.r.t. previous stores. */ 153 /* Ensure that the interrupt is ordered w.r.t. previous stores. */
@@ -359,15 +359,14 @@ mic_x100_load_command_line(struct mic_device *mdev, const struct firmware *fw)
359 359
360 boot_mem = mdev->aper.len >> 20; 360 boot_mem = mdev->aper.len >> 20;
361 buf = kzalloc(CMDLINE_SIZE, GFP_KERNEL); 361 buf = kzalloc(CMDLINE_SIZE, GFP_KERNEL);
362 if (!buf) { 362 if (!buf)
363 dev_err(mdev->sdev->parent,
364 "%s %d allocation failed\n", __func__, __LINE__);
365 return -ENOMEM; 363 return -ENOMEM;
366 } 364
367 len += snprintf(buf, CMDLINE_SIZE - len, 365 len += snprintf(buf, CMDLINE_SIZE - len,
368 " mem=%dM", boot_mem); 366 " mem=%dM", boot_mem);
369 if (mdev->cmdline) 367 if (mdev->cosm_dev->cmdline)
370 snprintf(buf + len, CMDLINE_SIZE - len, " %s", mdev->cmdline); 368 snprintf(buf + len, CMDLINE_SIZE - len, " %s",
369 mdev->cosm_dev->cmdline);
371 memcpy_toio(cmd_line_va, buf, strlen(buf) + 1); 370 memcpy_toio(cmd_line_va, buf, strlen(buf) + 1);
372 kfree(buf); 371 kfree(buf);
373 return 0; 372 return 0;
@@ -386,12 +385,11 @@ mic_x100_load_ramdisk(struct mic_device *mdev)
386 int rc; 385 int rc;
387 struct boot_params __iomem *bp = mdev->aper.va + mdev->bootaddr; 386 struct boot_params __iomem *bp = mdev->aper.va + mdev->bootaddr;
388 387
389 rc = request_firmware(&fw, 388 rc = request_firmware(&fw, mdev->cosm_dev->ramdisk, &mdev->pdev->dev);
390 mdev->ramdisk, mdev->sdev->parent);
391 if (rc < 0) { 389 if (rc < 0) {
392 dev_err(mdev->sdev->parent, 390 dev_err(&mdev->pdev->dev,
393 "ramdisk request_firmware failed: %d %s\n", 391 "ramdisk request_firmware failed: %d %s\n",
394 rc, mdev->ramdisk); 392 rc, mdev->cosm_dev->ramdisk);
395 goto error; 393 goto error;
396 } 394 }
397 /* 395 /*
@@ -423,10 +421,10 @@ mic_x100_get_boot_addr(struct mic_device *mdev)
423 421
424 scratch2 = mdev->ops->read_spad(mdev, MIC_X100_DOWNLOAD_INFO); 422 scratch2 = mdev->ops->read_spad(mdev, MIC_X100_DOWNLOAD_INFO);
425 boot_addr = MIC_X100_SPAD2_DOWNLOAD_ADDR(scratch2); 423 boot_addr = MIC_X100_SPAD2_DOWNLOAD_ADDR(scratch2);
426 dev_dbg(mdev->sdev->parent, "%s %d boot_addr 0x%x\n", 424 dev_dbg(&mdev->pdev->dev, "%s %d boot_addr 0x%x\n",
427 __func__, __LINE__, boot_addr); 425 __func__, __LINE__, boot_addr);
428 if (boot_addr > (1 << 31)) { 426 if (boot_addr > (1 << 31)) {
429 dev_err(mdev->sdev->parent, 427 dev_err(&mdev->pdev->dev,
430 "incorrect bootaddr 0x%x\n", 428 "incorrect bootaddr 0x%x\n",
431 boot_addr); 429 boot_addr);
432 rc = -EINVAL; 430 rc = -EINVAL;
@@ -454,37 +452,37 @@ mic_x100_load_firmware(struct mic_device *mdev, const char *buf)
454 if (rc) 452 if (rc)
455 goto error; 453 goto error;
456 /* load OS */ 454 /* load OS */
457 rc = request_firmware(&fw, mdev->firmware, mdev->sdev->parent); 455 rc = request_firmware(&fw, mdev->cosm_dev->firmware, &mdev->pdev->dev);
458 if (rc < 0) { 456 if (rc < 0) {
459 dev_err(mdev->sdev->parent, 457 dev_err(&mdev->pdev->dev,
460 "ramdisk request_firmware failed: %d %s\n", 458 "ramdisk request_firmware failed: %d %s\n",
461 rc, mdev->firmware); 459 rc, mdev->cosm_dev->firmware);
462 goto error; 460 goto error;
463 } 461 }
464 if (mdev->bootaddr > mdev->aper.len - fw->size) { 462 if (mdev->bootaddr > mdev->aper.len - fw->size) {
465 rc = -EINVAL; 463 rc = -EINVAL;
466 dev_err(mdev->sdev->parent, "%s %d rc %d bootaddr 0x%x\n", 464 dev_err(&mdev->pdev->dev, "%s %d rc %d bootaddr 0x%x\n",
467 __func__, __LINE__, rc, mdev->bootaddr); 465 __func__, __LINE__, rc, mdev->bootaddr);
468 release_firmware(fw); 466 release_firmware(fw);
469 goto error; 467 goto error;
470 } 468 }
471 memcpy_toio(mdev->aper.va + mdev->bootaddr, fw->data, fw->size); 469 memcpy_toio(mdev->aper.va + mdev->bootaddr, fw->data, fw->size);
472 mdev->ops->write_spad(mdev, MIC_X100_FW_SIZE, fw->size); 470 mdev->ops->write_spad(mdev, MIC_X100_FW_SIZE, fw->size);
473 if (!strcmp(mdev->bootmode, "elf")) 471 if (!strcmp(mdev->cosm_dev->bootmode, "flash"))
474 goto done; 472 goto done;
475 /* load command line */ 473 /* load command line */
476 rc = mic_x100_load_command_line(mdev, fw); 474 rc = mic_x100_load_command_line(mdev, fw);
477 if (rc) { 475 if (rc) {
478 dev_err(mdev->sdev->parent, "%s %d rc %d\n", 476 dev_err(&mdev->pdev->dev, "%s %d rc %d\n",
479 __func__, __LINE__, rc); 477 __func__, __LINE__, rc);
480 goto error; 478 goto error;
481 } 479 }
482 release_firmware(fw); 480 release_firmware(fw);
483 /* load ramdisk */ 481 /* load ramdisk */
484 if (mdev->ramdisk) 482 if (mdev->cosm_dev->ramdisk)
485 rc = mic_x100_load_ramdisk(mdev); 483 rc = mic_x100_load_ramdisk(mdev);
486error: 484error:
487 dev_dbg(mdev->sdev->parent, "%s %d rc %d\n", __func__, __LINE__, rc); 485 dev_dbg(&mdev->pdev->dev, "%s %d rc %d\n", __func__, __LINE__, rc);
488done: 486done:
489 return rc; 487 return rc;
490} 488}