1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for the HP iLO management processor.
5 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
6 * David Altobelli <david.altobelli@hpe.com>
8 #include <linux/kernel.h>
9 #include <linux/types.h>
10 #include <linux/module.h>
12 #include <linux/pci.h>
13 #include <linux/interrupt.h>
14 #include <linux/ioport.h>
15 #include <linux/device.h>
16 #include <linux/file.h>
17 #include <linux/cdev.h>
18 #include <linux/sched.h>
19 #include <linux/spinlock.h>
20 #include <linux/delay.h>
21 #include <linux/uaccess.h>
23 #include <linux/wait.h>
24 #include <linux/poll.h>
25 #include <linux/slab.h>
28 static const struct class ilo_class
= {
31 static unsigned int ilo_major
;
32 static unsigned int max_ccb
= 16;
33 static char ilo_hwdev
[MAX_ILO_DEV
];
34 static const struct pci_device_id ilo_blacklist
[] = {
36 {PCI_DEVICE_SUB(PCI_VENDOR_ID_HP
, 0x3307, PCI_VENDOR_ID_HP
, 0x1979)},
38 {PCI_DEVICE_SUB(PCI_VENDOR_ID_HP
, 0x3307, PCI_VENDOR_ID_HP_3PAR
, 0x0289)},
42 static inline int get_entry_id(int entry
)
44 return (entry
& ENTRY_MASK_DESCRIPTOR
) >> ENTRY_BITPOS_DESCRIPTOR
;
47 static inline int get_entry_len(int entry
)
49 return ((entry
& ENTRY_MASK_QWORDS
) >> ENTRY_BITPOS_QWORDS
) << 3;
52 static inline int mk_entry(int id
, int len
)
54 int qlen
= len
& 7 ? (len
>> 3) + 1 : len
>> 3;
55 return id
<< ENTRY_BITPOS_DESCRIPTOR
| qlen
<< ENTRY_BITPOS_QWORDS
;
58 static inline int desc_mem_sz(int nr_entry
)
60 return nr_entry
<< L2_QENTRY_SZ
;
64 * FIFO queues, shared with hardware.
66 * If a queue has empty slots, an entry is added to the queue tail,
67 * and that entry is marked as occupied.
68 * Entries can be dequeued from the head of the list, when the device
69 * has marked the entry as consumed.
71 * Returns true on successful queue/dequeue, false on failure.
73 static int fifo_enqueue(struct ilo_hwinfo
*hw
, char *fifobar
, int entry
)
75 struct fifo
*fifo_q
= FIFOBARTOHANDLE(fifobar
);
79 spin_lock_irqsave(&hw
->fifo_lock
, flags
);
80 if (!(fifo_q
->fifobar
[(fifo_q
->tail
+ 1) & fifo_q
->imask
]
82 fifo_q
->fifobar
[fifo_q
->tail
& fifo_q
->imask
] |=
83 (entry
& ENTRY_MASK_NOSTATE
) | fifo_q
->merge
;
87 spin_unlock_irqrestore(&hw
->fifo_lock
, flags
);
92 static int fifo_dequeue(struct ilo_hwinfo
*hw
, char *fifobar
, int *entry
)
94 struct fifo
*fifo_q
= FIFOBARTOHANDLE(fifobar
);
99 spin_lock_irqsave(&hw
->fifo_lock
, flags
);
100 c
= fifo_q
->fifobar
[fifo_q
->head
& fifo_q
->imask
];
101 if (c
& ENTRY_MASK_C
) {
103 *entry
= c
& ENTRY_MASK_NOSTATE
;
105 fifo_q
->fifobar
[fifo_q
->head
& fifo_q
->imask
] =
106 (c
| ENTRY_MASK
) + 1;
110 spin_unlock_irqrestore(&hw
->fifo_lock
, flags
);
115 static int fifo_check_recv(struct ilo_hwinfo
*hw
, char *fifobar
)
117 struct fifo
*fifo_q
= FIFOBARTOHANDLE(fifobar
);
122 spin_lock_irqsave(&hw
->fifo_lock
, flags
);
123 c
= fifo_q
->fifobar
[fifo_q
->head
& fifo_q
->imask
];
124 if (c
& ENTRY_MASK_C
)
126 spin_unlock_irqrestore(&hw
->fifo_lock
, flags
);
131 static int ilo_pkt_enqueue(struct ilo_hwinfo
*hw
, struct ccb
*ccb
,
132 int dir
, int id
, int len
)
138 fifobar
= ccb
->ccb_u1
.send_fifobar
;
140 fifobar
= ccb
->ccb_u3
.recv_fifobar
;
142 entry
= mk_entry(id
, len
);
143 return fifo_enqueue(hw
, fifobar
, entry
);
146 static int ilo_pkt_dequeue(struct ilo_hwinfo
*hw
, struct ccb
*ccb
,
147 int dir
, int *id
, int *len
, void **pkt
)
149 char *fifobar
, *desc
;
150 int entry
= 0, pkt_id
= 0;
154 fifobar
= ccb
->ccb_u1
.send_fifobar
;
155 desc
= ccb
->ccb_u2
.send_desc
;
157 fifobar
= ccb
->ccb_u3
.recv_fifobar
;
158 desc
= ccb
->ccb_u4
.recv_desc
;
161 ret
= fifo_dequeue(hw
, fifobar
, &entry
);
163 pkt_id
= get_entry_id(entry
);
167 *len
= get_entry_len(entry
);
169 *pkt
= (void *)(desc
+ desc_mem_sz(pkt_id
));
175 static int ilo_pkt_recv(struct ilo_hwinfo
*hw
, struct ccb
*ccb
)
177 char *fifobar
= ccb
->ccb_u3
.recv_fifobar
;
179 return fifo_check_recv(hw
, fifobar
);
182 static inline void doorbell_set(struct ccb
*ccb
)
184 iowrite8(1, ccb
->ccb_u5
.db_base
);
187 static inline void doorbell_clr(struct ccb
*ccb
)
189 iowrite8(2, ccb
->ccb_u5
.db_base
);
192 static inline int ctrl_set(int l2sz
, int idxmask
, int desclim
)
194 int active
= 0, go
= 1;
195 return l2sz
<< CTRL_BITPOS_L2SZ
|
196 idxmask
<< CTRL_BITPOS_FIFOINDEXMASK
|
197 desclim
<< CTRL_BITPOS_DESCLIMIT
|
198 active
<< CTRL_BITPOS_A
|
202 static void ctrl_setup(struct ccb
*ccb
, int nr_desc
, int l2desc_sz
)
204 /* for simplicity, use the same parameters for send and recv ctrls */
205 ccb
->send_ctrl
= ctrl_set(l2desc_sz
, nr_desc
-1, nr_desc
-1);
206 ccb
->recv_ctrl
= ctrl_set(l2desc_sz
, nr_desc
-1, nr_desc
-1);
209 static inline int fifo_sz(int nr_entry
)
211 /* size of a fifo is determined by the number of entries it contains */
212 return nr_entry
* sizeof(u64
) + FIFOHANDLESIZE
;
215 static void fifo_setup(void *base_addr
, int nr_entry
)
217 struct fifo
*fifo_q
= base_addr
;
220 /* set up an empty fifo */
224 fifo_q
->nrents
= nr_entry
;
225 fifo_q
->imask
= nr_entry
- 1;
226 fifo_q
->merge
= ENTRY_MASK_O
;
228 for (i
= 0; i
< nr_entry
; i
++)
229 fifo_q
->fifobar
[i
] = 0;
232 static void ilo_ccb_close(struct pci_dev
*pdev
, struct ccb_data
*data
)
234 struct ccb
*driver_ccb
= &data
->driver_ccb
;
235 struct ccb __iomem
*device_ccb
= data
->mapped_ccb
;
238 /* complicated dance to tell the hw we are stopping */
239 doorbell_clr(driver_ccb
);
240 iowrite32(ioread32(&device_ccb
->send_ctrl
) & ~(1 << CTRL_BITPOS_G
),
241 &device_ccb
->send_ctrl
);
242 iowrite32(ioread32(&device_ccb
->recv_ctrl
) & ~(1 << CTRL_BITPOS_G
),
243 &device_ccb
->recv_ctrl
);
245 /* give iLO some time to process stop request */
246 for (retries
= MAX_WAIT
; retries
> 0; retries
--) {
247 doorbell_set(driver_ccb
);
249 if (!(ioread32(&device_ccb
->send_ctrl
) & (1 << CTRL_BITPOS_A
))
251 !(ioread32(&device_ccb
->recv_ctrl
) & (1 << CTRL_BITPOS_A
)))
255 dev_err(&pdev
->dev
, "Closing, but controller still active\n");
257 /* clear the hw ccb */
258 memset_io(device_ccb
, 0, sizeof(struct ccb
));
260 /* free resources used to back send/recv queues */
261 dma_free_coherent(&pdev
->dev
, data
->dma_size
, data
->dma_va
,
265 static int ilo_ccb_setup(struct ilo_hwinfo
*hw
, struct ccb_data
*data
, int slot
)
269 struct ccb
*driver_ccb
, *ilo_ccb
;
271 driver_ccb
= &data
->driver_ccb
;
272 ilo_ccb
= &data
->ilo_ccb
;
274 data
->dma_size
= 2 * fifo_sz(NR_QENTRY
) +
275 2 * desc_mem_sz(NR_QENTRY
) +
276 ILO_START_ALIGN
+ ILO_CACHE_SZ
;
278 data
->dma_va
= dma_alloc_coherent(&hw
->ilo_dev
->dev
, data
->dma_size
,
279 &data
->dma_pa
, GFP_ATOMIC
);
283 dma_va
= (char *)data
->dma_va
;
284 dma_pa
= data
->dma_pa
;
286 dma_va
= (char *)roundup((unsigned long)dma_va
, ILO_START_ALIGN
);
287 dma_pa
= roundup(dma_pa
, ILO_START_ALIGN
);
290 * Create two ccb's, one with virt addrs, one with phys addrs.
291 * Copy the phys addr ccb to device shared mem.
293 ctrl_setup(driver_ccb
, NR_QENTRY
, L2_QENTRY_SZ
);
294 ctrl_setup(ilo_ccb
, NR_QENTRY
, L2_QENTRY_SZ
);
296 fifo_setup(dma_va
, NR_QENTRY
);
297 driver_ccb
->ccb_u1
.send_fifobar
= dma_va
+ FIFOHANDLESIZE
;
298 ilo_ccb
->ccb_u1
.send_fifobar_pa
= dma_pa
+ FIFOHANDLESIZE
;
299 dma_va
+= fifo_sz(NR_QENTRY
);
300 dma_pa
+= fifo_sz(NR_QENTRY
);
302 dma_va
= (char *)roundup((unsigned long)dma_va
, ILO_CACHE_SZ
);
303 dma_pa
= roundup(dma_pa
, ILO_CACHE_SZ
);
305 fifo_setup(dma_va
, NR_QENTRY
);
306 driver_ccb
->ccb_u3
.recv_fifobar
= dma_va
+ FIFOHANDLESIZE
;
307 ilo_ccb
->ccb_u3
.recv_fifobar_pa
= dma_pa
+ FIFOHANDLESIZE
;
308 dma_va
+= fifo_sz(NR_QENTRY
);
309 dma_pa
+= fifo_sz(NR_QENTRY
);
311 driver_ccb
->ccb_u2
.send_desc
= dma_va
;
312 ilo_ccb
->ccb_u2
.send_desc_pa
= dma_pa
;
313 dma_pa
+= desc_mem_sz(NR_QENTRY
);
314 dma_va
+= desc_mem_sz(NR_QENTRY
);
316 driver_ccb
->ccb_u4
.recv_desc
= dma_va
;
317 ilo_ccb
->ccb_u4
.recv_desc_pa
= dma_pa
;
319 driver_ccb
->channel
= slot
;
320 ilo_ccb
->channel
= slot
;
322 driver_ccb
->ccb_u5
.db_base
= hw
->db_vaddr
+ (slot
<< L2_DB_SIZE
);
323 ilo_ccb
->ccb_u5
.db_base
= NULL
; /* hw ccb's doorbell is not used */
328 static void ilo_ccb_open(struct ilo_hwinfo
*hw
, struct ccb_data
*data
, int slot
)
331 struct ccb
*driver_ccb
= &data
->driver_ccb
;
333 /* copy the ccb with physical addrs to device memory */
334 data
->mapped_ccb
= (struct ccb __iomem
*)
335 (hw
->ram_vaddr
+ (slot
* ILOHW_CCB_SZ
));
336 memcpy_toio(data
->mapped_ccb
, &data
->ilo_ccb
, sizeof(struct ccb
));
338 /* put packets on the send and receive queues */
340 for (pkt_id
= 0; pkt_id
< NR_QENTRY
; pkt_id
++) {
341 ilo_pkt_enqueue(hw
, driver_ccb
, SENDQ
, pkt_id
, pkt_sz
);
342 doorbell_set(driver_ccb
);
345 pkt_sz
= desc_mem_sz(1);
346 for (pkt_id
= 0; pkt_id
< NR_QENTRY
; pkt_id
++)
347 ilo_pkt_enqueue(hw
, driver_ccb
, RECVQ
, pkt_id
, pkt_sz
);
349 /* the ccb is ready to use */
350 doorbell_clr(driver_ccb
);
353 static int ilo_ccb_verify(struct ilo_hwinfo
*hw
, struct ccb_data
*data
)
356 struct ccb
*driver_ccb
= &data
->driver_ccb
;
358 /* make sure iLO is really handling requests */
359 for (i
= MAX_WAIT
; i
> 0; i
--) {
360 if (ilo_pkt_dequeue(hw
, driver_ccb
, SENDQ
, &pkt_id
, NULL
, NULL
))
366 dev_err(&hw
->ilo_dev
->dev
, "Open could not dequeue a packet\n");
370 ilo_pkt_enqueue(hw
, driver_ccb
, SENDQ
, pkt_id
, 0);
371 doorbell_set(driver_ccb
);
375 static inline int is_channel_reset(struct ccb
*ccb
)
377 /* check for this particular channel needing a reset */
378 return FIFOBARTOHANDLE(ccb
->ccb_u1
.send_fifobar
)->reset
;
381 static inline void set_channel_reset(struct ccb
*ccb
)
383 /* set a flag indicating this channel needs a reset */
384 FIFOBARTOHANDLE(ccb
->ccb_u1
.send_fifobar
)->reset
= 1;
387 static inline int get_device_outbound(struct ilo_hwinfo
*hw
)
389 return ioread32(&hw
->mmio_vaddr
[DB_OUT
]);
392 static inline int is_db_reset(int db_out
)
394 return db_out
& (1 << DB_RESET
);
397 static inline void clear_pending_db(struct ilo_hwinfo
*hw
, int clr
)
399 iowrite32(clr
, &hw
->mmio_vaddr
[DB_OUT
]);
402 static inline void clear_device(struct ilo_hwinfo
*hw
)
404 /* clear the device (reset bits, pending channel entries) */
405 clear_pending_db(hw
, -1);
408 static inline void ilo_enable_interrupts(struct ilo_hwinfo
*hw
)
410 iowrite8(ioread8(&hw
->mmio_vaddr
[DB_IRQ
]) | 1, &hw
->mmio_vaddr
[DB_IRQ
]);
413 static inline void ilo_disable_interrupts(struct ilo_hwinfo
*hw
)
415 iowrite8(ioread8(&hw
->mmio_vaddr
[DB_IRQ
]) & ~1,
416 &hw
->mmio_vaddr
[DB_IRQ
]);
419 static void ilo_set_reset(struct ilo_hwinfo
*hw
)
424 * Mapped memory is zeroed on ilo reset, so set a per ccb flag
425 * to indicate that this ccb needs to be closed and reopened.
427 for (slot
= 0; slot
< max_ccb
; slot
++) {
428 if (!hw
->ccb_alloc
[slot
])
430 set_channel_reset(&hw
->ccb_alloc
[slot
]->driver_ccb
);
434 static ssize_t
ilo_read(struct file
*fp
, char __user
*buf
,
435 size_t len
, loff_t
*off
)
437 int err
, found
, cnt
, pkt_id
, pkt_len
;
438 struct ccb_data
*data
= fp
->private_data
;
439 struct ccb
*driver_ccb
= &data
->driver_ccb
;
440 struct ilo_hwinfo
*hw
= data
->ilo_hw
;
443 if (is_channel_reset(driver_ccb
)) {
445 * If the device has been reset, applications
446 * need to close and reopen all ccbs.
452 * This function is to be called when data is expected
453 * in the channel, and will return an error if no packet is found
454 * during the loop below. The sleep/retry logic is to allow
455 * applications to call read() immediately post write(),
456 * and give iLO some time to process the sent packet.
460 /* look for a received packet */
461 found
= ilo_pkt_dequeue(hw
, driver_ccb
, RECVQ
, &pkt_id
,
467 } while (!found
&& cnt
);
472 /* only copy the length of the received packet */
476 err
= copy_to_user(buf
, pkt
, len
);
478 /* return the received packet to the queue */
479 ilo_pkt_enqueue(hw
, driver_ccb
, RECVQ
, pkt_id
, desc_mem_sz(1));
481 return err
? -EFAULT
: len
;
484 static ssize_t
ilo_write(struct file
*fp
, const char __user
*buf
,
485 size_t len
, loff_t
*off
)
487 int err
, pkt_id
, pkt_len
;
488 struct ccb_data
*data
= fp
->private_data
;
489 struct ccb
*driver_ccb
= &data
->driver_ccb
;
490 struct ilo_hwinfo
*hw
= data
->ilo_hw
;
493 if (is_channel_reset(driver_ccb
))
496 /* get a packet to send the user command */
497 if (!ilo_pkt_dequeue(hw
, driver_ccb
, SENDQ
, &pkt_id
, &pkt_len
, &pkt
))
500 /* limit the length to the length of the packet */
504 /* on failure, set the len to 0 to return empty packet to the device */
505 err
= copy_from_user(pkt
, buf
, len
);
509 /* send the packet */
510 ilo_pkt_enqueue(hw
, driver_ccb
, SENDQ
, pkt_id
, len
);
511 doorbell_set(driver_ccb
);
513 return err
? -EFAULT
: len
;
516 static __poll_t
ilo_poll(struct file
*fp
, poll_table
*wait
)
518 struct ccb_data
*data
= fp
->private_data
;
519 struct ccb
*driver_ccb
= &data
->driver_ccb
;
521 poll_wait(fp
, &data
->ccb_waitq
, wait
);
523 if (is_channel_reset(driver_ccb
))
525 else if (ilo_pkt_recv(data
->ilo_hw
, driver_ccb
))
526 return EPOLLIN
| EPOLLRDNORM
;
531 static int ilo_close(struct inode
*ip
, struct file
*fp
)
534 struct ccb_data
*data
;
535 struct ilo_hwinfo
*hw
;
538 slot
= iminor(ip
) % max_ccb
;
539 hw
= container_of(ip
->i_cdev
, struct ilo_hwinfo
, cdev
);
541 spin_lock(&hw
->open_lock
);
543 if (hw
->ccb_alloc
[slot
]->ccb_cnt
== 1) {
545 data
= fp
->private_data
;
547 spin_lock_irqsave(&hw
->alloc_lock
, flags
);
548 hw
->ccb_alloc
[slot
] = NULL
;
549 spin_unlock_irqrestore(&hw
->alloc_lock
, flags
);
551 ilo_ccb_close(hw
->ilo_dev
, data
);
555 hw
->ccb_alloc
[slot
]->ccb_cnt
--;
557 spin_unlock(&hw
->open_lock
);
562 static int ilo_open(struct inode
*ip
, struct file
*fp
)
565 struct ccb_data
*data
;
566 struct ilo_hwinfo
*hw
;
569 slot
= iminor(ip
) % max_ccb
;
570 hw
= container_of(ip
->i_cdev
, struct ilo_hwinfo
, cdev
);
572 /* new ccb allocation */
573 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
577 spin_lock(&hw
->open_lock
);
579 /* each fd private_data holds sw/hw view of ccb */
580 if (hw
->ccb_alloc
[slot
] == NULL
) {
581 /* create a channel control block for this minor */
582 error
= ilo_ccb_setup(hw
, data
, slot
);
589 data
->ccb_excl
= fp
->f_flags
& O_EXCL
;
591 init_waitqueue_head(&data
->ccb_waitq
);
593 /* write the ccb to hw */
594 spin_lock_irqsave(&hw
->alloc_lock
, flags
);
595 ilo_ccb_open(hw
, data
, slot
);
596 hw
->ccb_alloc
[slot
] = data
;
597 spin_unlock_irqrestore(&hw
->alloc_lock
, flags
);
599 /* make sure the channel is functional */
600 error
= ilo_ccb_verify(hw
, data
);
603 spin_lock_irqsave(&hw
->alloc_lock
, flags
);
604 hw
->ccb_alloc
[slot
] = NULL
;
605 spin_unlock_irqrestore(&hw
->alloc_lock
, flags
);
607 ilo_ccb_close(hw
->ilo_dev
, data
);
615 if (fp
->f_flags
& O_EXCL
|| hw
->ccb_alloc
[slot
]->ccb_excl
) {
617 * The channel exists, and either this open
618 * or a previous open of this channel wants
623 hw
->ccb_alloc
[slot
]->ccb_cnt
++;
628 spin_unlock(&hw
->open_lock
);
631 fp
->private_data
= hw
->ccb_alloc
[slot
];
636 static const struct file_operations ilo_fops
= {
637 .owner
= THIS_MODULE
,
642 .release
= ilo_close
,
643 .llseek
= noop_llseek
,
646 static irqreturn_t
ilo_isr(int irq
, void *data
)
648 struct ilo_hwinfo
*hw
= data
;
651 spin_lock(&hw
->alloc_lock
);
653 /* check for ccbs which have data */
654 pending
= get_device_outbound(hw
);
656 spin_unlock(&hw
->alloc_lock
);
660 if (is_db_reset(pending
)) {
661 /* wake up all ccbs if the device was reset */
666 for (i
= 0; i
< max_ccb
; i
++) {
667 if (!hw
->ccb_alloc
[i
])
669 if (pending
& (1 << i
))
670 wake_up_interruptible(&hw
->ccb_alloc
[i
]->ccb_waitq
);
673 /* clear the device of the channels that have been handled */
674 clear_pending_db(hw
, pending
);
676 spin_unlock(&hw
->alloc_lock
);
681 static void ilo_unmap_device(struct pci_dev
*pdev
, struct ilo_hwinfo
*hw
)
683 pci_iounmap(pdev
, hw
->db_vaddr
);
684 pci_iounmap(pdev
, hw
->ram_vaddr
);
685 pci_iounmap(pdev
, hw
->mmio_vaddr
);
688 static int ilo_map_device(struct pci_dev
*pdev
, struct ilo_hwinfo
*hw
)
695 /* map the memory mapped i/o registers */
696 hw
->mmio_vaddr
= pci_iomap(pdev
, 1, 0);
697 if (hw
->mmio_vaddr
== NULL
) {
698 dev_err(&pdev
->dev
, "Error mapping mmio\n");
702 /* map the adapter shared memory region */
703 rc
= pci_read_config_byte(pdev
, PCI_REVISION_ID
, &pci_rev_id
);
705 dev_err(&pdev
->dev
, "Error reading PCI rev id: %d\n", rc
);
709 if (pci_rev_id
>= PCI_REV_ID_NECHES
) {
711 /* Last 8k is reserved for CCBs */
712 off
= pci_resource_len(pdev
, bar
) - 0x2000;
717 hw
->ram_vaddr
= pci_iomap_range(pdev
, bar
, off
, max_ccb
* ILOHW_CCB_SZ
);
718 if (hw
->ram_vaddr
== NULL
) {
719 dev_err(&pdev
->dev
, "Error mapping shared mem\n");
723 /* map the doorbell aperture */
724 hw
->db_vaddr
= pci_iomap(pdev
, 3, max_ccb
* ONE_DB_SIZE
);
725 if (hw
->db_vaddr
== NULL
) {
726 dev_err(&pdev
->dev
, "Error mapping doorbell\n");
732 pci_iounmap(pdev
, hw
->ram_vaddr
);
734 pci_iounmap(pdev
, hw
->mmio_vaddr
);
739 static void ilo_remove(struct pci_dev
*pdev
)
742 struct ilo_hwinfo
*ilo_hw
= pci_get_drvdata(pdev
);
747 clear_device(ilo_hw
);
749 minor
= MINOR(ilo_hw
->cdev
.dev
);
750 for (i
= minor
; i
< minor
+ max_ccb
; i
++)
751 device_destroy(&ilo_class
, MKDEV(ilo_major
, i
));
753 cdev_del(&ilo_hw
->cdev
);
754 ilo_disable_interrupts(ilo_hw
);
755 free_irq(pdev
->irq
, ilo_hw
);
756 ilo_unmap_device(pdev
, ilo_hw
);
757 pci_release_regions(pdev
);
759 * pci_disable_device(pdev) used to be here. But this PCI device has
760 * two functions with interrupt lines connected to a single pin. The
761 * other one is a USB host controller. So when we disable the PIN here
762 * e.g. by rmmod hpilo, the controller stops working. It is because
763 * the interrupt link is disabled in ACPI since it is not refcounted
764 * yet. See acpi_pci_link_free_irq called from acpi_pci_irq_disable.
767 ilo_hwdev
[(minor
/ max_ccb
)] = 0;
770 static int ilo_probe(struct pci_dev
*pdev
,
771 const struct pci_device_id
*ent
)
773 int devnum
, slot
, start
, error
= 0;
774 struct ilo_hwinfo
*ilo_hw
;
776 if (pci_match_id(ilo_blacklist
, pdev
)) {
777 dev_dbg(&pdev
->dev
, "Not supported on this device\n");
781 if (max_ccb
> MAX_CCB
)
783 else if (max_ccb
< MIN_CCB
)
786 /* find a free range for device files */
787 for (devnum
= 0; devnum
< MAX_ILO_DEV
; devnum
++) {
788 if (ilo_hwdev
[devnum
] == 0) {
789 ilo_hwdev
[devnum
] = 1;
794 if (devnum
== MAX_ILO_DEV
) {
795 dev_err(&pdev
->dev
, "Error finding free device\n");
799 /* track global allocations for this device */
801 ilo_hw
= kzalloc(sizeof(*ilo_hw
), GFP_KERNEL
);
805 ilo_hw
->ilo_dev
= pdev
;
806 spin_lock_init(&ilo_hw
->alloc_lock
);
807 spin_lock_init(&ilo_hw
->fifo_lock
);
808 spin_lock_init(&ilo_hw
->open_lock
);
810 error
= pci_enable_device(pdev
);
814 pci_set_master(pdev
);
816 error
= pci_request_regions(pdev
, ILO_NAME
);
820 error
= ilo_map_device(pdev
, ilo_hw
);
824 pci_set_drvdata(pdev
, ilo_hw
);
825 clear_device(ilo_hw
);
827 error
= request_irq(pdev
->irq
, ilo_isr
, IRQF_SHARED
, "hpilo", ilo_hw
);
831 ilo_enable_interrupts(ilo_hw
);
833 cdev_init(&ilo_hw
->cdev
, &ilo_fops
);
834 ilo_hw
->cdev
.owner
= THIS_MODULE
;
835 start
= devnum
* max_ccb
;
836 error
= cdev_add(&ilo_hw
->cdev
, MKDEV(ilo_major
, start
), max_ccb
);
838 dev_err(&pdev
->dev
, "Could not add cdev\n");
842 for (slot
= 0; slot
< max_ccb
; slot
++) {
844 dev
= device_create(&ilo_class
, &pdev
->dev
,
845 MKDEV(ilo_major
, start
+ slot
), NULL
,
846 "hpilo!d%dccb%d", devnum
, slot
);
848 dev_err(&pdev
->dev
, "Could not create files\n");
853 ilo_disable_interrupts(ilo_hw
);
854 free_irq(pdev
->irq
, ilo_hw
);
856 ilo_unmap_device(pdev
, ilo_hw
);
858 pci_release_regions(pdev
);
860 /* pci_disable_device(pdev); see comment in ilo_remove */
864 ilo_hwdev
[devnum
] = 0;
868 static const struct pci_device_id ilo_devices
[] = {
869 { PCI_DEVICE(PCI_VENDOR_ID_COMPAQ
, 0xB204) },
870 { PCI_DEVICE(PCI_VENDOR_ID_HP
, 0x3307) },
873 MODULE_DEVICE_TABLE(pci
, ilo_devices
);
875 static struct pci_driver ilo_driver
= {
877 .id_table
= ilo_devices
,
879 .remove
= ilo_remove
,
882 static int __init
ilo_init(void)
887 error
= class_register(&ilo_class
);
891 error
= alloc_chrdev_region(&dev
, 0, MAX_OPEN
, ILO_NAME
);
895 ilo_major
= MAJOR(dev
);
897 error
= pci_register_driver(&ilo_driver
);
903 unregister_chrdev_region(dev
, MAX_OPEN
);
905 class_unregister(&ilo_class
);
910 static void __exit
ilo_exit(void)
912 pci_unregister_driver(&ilo_driver
);
913 unregister_chrdev_region(MKDEV(ilo_major
, 0), MAX_OPEN
);
914 class_unregister(&ilo_class
);
917 MODULE_VERSION("1.5.0");
918 MODULE_ALIAS(ILO_NAME
);
919 MODULE_DESCRIPTION(ILO_NAME
);
920 MODULE_AUTHOR("David Altobelli <david.altobelli@hpe.com>");
921 MODULE_LICENSE("GPL v2");
923 module_param(max_ccb
, uint
, 0444);
924 MODULE_PARM_DESC(max_ccb
, "Maximum number of HP iLO channels to attach (8-24)(default=16)");
926 module_init(ilo_init
);
927 module_exit(ilo_exit
);