32 #include <linux/kernel.h>
34 #include <linux/types.h>
35 #include <linux/pci.h>
37 #include <linux/slab.h>
44 #include <asm/uaccess.h>
57 # define AAC_DEBUG_PREAMBLE KERN_INFO
58 # define AAC_DEBUG_POSTAMBLE
60 static int ioctl_send_fib(
struct aac_dev *
dev,
void __user *
arg)
127 kfib->
header.XferState = 0;
169 static int open_getadapter_fib(
struct aac_dev *
dev,
void __user *
arg)
175 if (fibctx ==
NULL) {
221 spin_unlock_irqrestore(&dev->
fib_lock, flags);
223 sizeof(fibctx->
unique))) {
241 static int next_getadapter_fib(
struct aac_dev * dev,
void __user *arg)
267 if (fibctx->
unique ==
f.fibctx) {
274 spin_unlock_irqrestore(&dev->
fib_lock, flags);
281 spin_unlock_irqrestore(&dev->
fib_lock, flags);
291 if (!list_empty(&fibctx->
fib_list)) {
300 spin_unlock_irqrestore(&dev->
fib_lock, flags);
313 spin_unlock_irqrestore(&dev->
fib_lock, flags);
347 while (!list_empty(&fibctx->
fib_list)) {
385 static int close_getadapter_fib(
struct aac_dev * dev,
void __user *arg)
421 spin_unlock_irqrestore(&dev->
fib_lock, flags);
435 static int check_revision(
struct aac_dev *dev,
void __user *arg)
443 &driver_version, 10) << 24) | 0x00000400;
444 version +=
simple_strtol(driver_version + 1, &driver_version, 10) << 16;
447 # ifdef AAC_DRIVER_BUILD
465 static int aac_send_raw_srb(
struct aac_dev* dev,
void __user * arg)
482 u32 actual_fibsize64, actual_fibsize = 0;
506 memset(sg_list, 0,
sizeof(sg_list));
530 user_reply = arg+fibsize;
532 flags = user_srbcmd->
flags;
566 actual_fibsize64 = actual_fibsize + (user_srbcmd->
sg.count & 0xff) *
569 if ((actual_fibsize != fibsize) && (actual_fibsize64 != fibsize)) {
571 "Raw SRB command calculated fibsize=%lu;%lu "
572 "user_srbcmd->sg.count=%d aac_srb=%lu sgentry=%lu;%lu "
573 "issued fibsize=%d\n",
574 actual_fibsize, actual_fibsize64, user_srbcmd->
sg.count,
580 if ((data_dir ==
DMA_NONE) && user_srbcmd->
sg.count) {
581 dprintk((
KERN_DEBUG"aacraid: SG with no direction specified in Raw SRB command\n"));
593 if (actual_fibsize64 == fibsize) {
594 actual_fibsize = actual_fibsize64;
595 for (i = 0; i < upsg->
count; i++) {
598 if (upsg->
sg[i].count >
609 dprintk((
KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
610 upsg->
sg[i].count,i,upsg->
count));
614 addr = (
u64)upsg->
sg[i].addr[0];
615 addr += ((
u64)upsg->
sg[
i].addr[1]) << 32;
627 addr = pci_map_single(dev->
pdev, p, upsg->
sg[i].count, data_dir);
631 byte_count += upsg->
sg[
i].count;
644 +
sizeof(
struct sgmap));
645 actual_fibsize = actual_fibsize64;
647 for (i = 0; i < usg->
count; i++) {
650 if (usg->
sg[i].count >
662 dprintk((
KERN_DEBUG "aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
663 usg->
sg[i].count,i,usg->
count));
672 if (flags & SRB_DataOut) {
680 addr = pci_map_single(dev->
pdev, p, usg->
sg[i].count, data_dir);
684 byte_count += usg->
sg[
i].count;
694 struct sgmap* psg = &srbcmd->
sg;
696 if (actual_fibsize64 == fibsize) {
698 for (i = 0; i < upsg->
count; i++) {
701 if (usg->
sg[i].count >
712 dprintk((
KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
713 usg->
sg[i].count,i,usg->
count));
717 addr = (
u64)usg->
sg[i].addr[0];
718 addr += ((
u64)usg->
sg[
i].addr[1]) << 32;
719 sg_user[
i] = (
void __user *)addr;
723 if (flags & SRB_DataOut) {
730 addr = pci_map_single(dev->
pdev, p, usg->
sg[i].count, data_dir);
733 byte_count += usg->
sg[
i].count;
737 for (i = 0; i < upsg->
count; i++) {
740 if (upsg->
sg[i].count >
750 dprintk((
KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
751 upsg->
sg[i].count, i, upsg->
count));
759 if (flags & SRB_DataOut) {
761 upsg->
sg[i].count)) {
767 addr = pci_map_single(dev->
pdev, p,
768 upsg->
sg[i].count, data_dir);
771 byte_count += upsg->
sg[
i].count;
791 for(i = 0 ; i <= sg_indx; i++){
794 ? ((
struct sgmap64*)&srbcmd->
sg)->sg[i].count
795 : srbcmd->
sg.sg[i].count);
814 for(i=0; i <= sg_indx; i++){
831 static int aac_get_pci_info(
struct aac_dev* dev,
void __user *arg)
835 pci_info.
bus = dev->
pdev->bus->number;
860 status = check_revision(dev, arg);
864 status = ioctl_send_fib(dev, arg);
867 status = open_getadapter_fib(dev, arg);
870 status = next_getadapter_fib(dev, arg);
873 status = close_getadapter_fib(dev, arg);
876 status = aac_send_raw_srb(dev,arg);
879 status = aac_get_pci_info(dev,arg);