Deleted Added
full compact
mrsas.c (272735) mrsas.c (272737)
1/*
2 * Copyright (c) 2014, LSI Corp.
3 * All rights reserved.
4 * Author: Marian Choy
5 * Support: freebsdraid@lsi.com
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 28 unchanged lines hidden (view full) ---

37 *
38 * Send feedback to: <megaraidfbsd@lsi.com>
39 * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035
40 * ATTN: MegaRaid FreeBSD
41 *
42 */
43
44#include <sys/cdefs.h>
1/*
2 * Copyright (c) 2014, LSI Corp.
3 * All rights reserved.
4 * Author: Marian Choy
5 * Support: freebsdraid@lsi.com
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 28 unchanged lines hidden (view full) ---

37 *
38 * Send feedback to: <megaraidfbsd@lsi.com>
39 * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035
40 * ATTN: MegaRaid FreeBSD
41 *
42 */
43
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/sys/dev/mrsas/mrsas.c 272735 2014-10-08 08:48:18Z kadesai $");
45__FBSDID("$FreeBSD: head/sys/dev/mrsas/mrsas.c 272737 2014-10-08 09:19:35Z kadesai $");
46
47#include <dev/mrsas/mrsas.h>
48#include <dev/mrsas/mrsas_ioctl.h>
49
50#include <cam/cam.h>
51#include <cam/cam_ccb.h>
52
53#include <sys/sysctl.h>

--- 6 unchanged lines hidden (view full) ---

60 * Function prototypes
61 */
62static d_open_t mrsas_open;
63static d_close_t mrsas_close;
64static d_read_t mrsas_read;
65static d_write_t mrsas_write;
66static d_ioctl_t mrsas_ioctl;
67
46
47#include <dev/mrsas/mrsas.h>
48#include <dev/mrsas/mrsas_ioctl.h>
49
50#include <cam/cam.h>
51#include <cam/cam_ccb.h>
52
53#include <sys/sysctl.h>

--- 6 unchanged lines hidden (view full) ---

60 * Function prototypes
61 */
62static d_open_t mrsas_open;
63static d_close_t mrsas_close;
64static d_read_t mrsas_read;
65static d_write_t mrsas_write;
66static d_ioctl_t mrsas_ioctl;
67
68static struct mrsas_mgmt_info mrsas_mgmt_info;
68static struct mrsas_ident *mrsas_find_ident(device_t);
69static void mrsas_shutdown_ctlr(struct mrsas_softc *sc, u_int32_t opcode);
70static void mrsas_flush_cache(struct mrsas_softc *sc);
71static void mrsas_reset_reply_desc(struct mrsas_softc *sc);
72static void mrsas_ocr_thread(void *arg);
73static int mrsas_get_map_info(struct mrsas_softc *sc);
74static int mrsas_get_ld_map_info(struct mrsas_softc *sc);
75static int mrsas_sync_map_info(struct mrsas_softc *sc);

--- 56 unchanged lines hidden (view full) ---

132
133extern int mrsas_cam_attach(struct mrsas_softc *sc);
134extern void mrsas_cam_detach(struct mrsas_softc *sc);
135extern void mrsas_cmd_done(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd);
136extern void mrsas_free_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
137extern int mrsas_alloc_mfi_cmds(struct mrsas_softc *sc);
138extern void mrsas_release_mpt_cmd(struct mrsas_mpt_cmd *cmd);
139extern struct mrsas_mpt_cmd *mrsas_get_mpt_cmd(struct mrsas_softc *sc);
69static struct mrsas_ident *mrsas_find_ident(device_t);
70static void mrsas_shutdown_ctlr(struct mrsas_softc *sc, u_int32_t opcode);
71static void mrsas_flush_cache(struct mrsas_softc *sc);
72static void mrsas_reset_reply_desc(struct mrsas_softc *sc);
73static void mrsas_ocr_thread(void *arg);
74static int mrsas_get_map_info(struct mrsas_softc *sc);
75static int mrsas_get_ld_map_info(struct mrsas_softc *sc);
76static int mrsas_sync_map_info(struct mrsas_softc *sc);

--- 56 unchanged lines hidden (view full) ---

133
134extern int mrsas_cam_attach(struct mrsas_softc *sc);
135extern void mrsas_cam_detach(struct mrsas_softc *sc);
136extern void mrsas_cmd_done(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd);
137extern void mrsas_free_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
138extern int mrsas_alloc_mfi_cmds(struct mrsas_softc *sc);
139extern void mrsas_release_mpt_cmd(struct mrsas_mpt_cmd *cmd);
140extern struct mrsas_mpt_cmd *mrsas_get_mpt_cmd(struct mrsas_softc *sc);
140extern int mrsas_passthru(struct mrsas_softc *sc, void *arg);
141extern int mrsas_passthru(struct mrsas_softc *sc, void *arg, u_long ioctlCmd);
141extern uint8_t MR_ValidateMapInfo(struct mrsas_softc *sc);
142extern u_int16_t MR_GetLDTgtId(u_int32_t ld, MR_DRV_RAID_MAP_ALL *map);
143extern MR_LD_RAID *MR_LdRaidGet(u_int32_t ld, MR_DRV_RAID_MAP_ALL *map);
144extern void mrsas_xpt_freeze(struct mrsas_softc *sc);
145extern void mrsas_xpt_release(struct mrsas_softc *sc);
146extern MRSAS_REQUEST_DESCRIPTOR_UNION *mrsas_get_request_desc(struct mrsas_softc *sc,
147 u_int16_t index);
148extern int mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim);

--- 503 unchanged lines hidden (view full) ---

652 dcmd->cmd_status = 0x0;
653 dcmd->sge_count = 1;
654 dcmd->flags = MFI_FRAME_DIR_READ;
655 dcmd->timeout = 0;
656 dcmd->pad_0 = 0;
657 dcmd->data_xfer_len = sizeof(struct mrsas_evt_detail);
658 dcmd->opcode = MR_DCMD_CTRL_EVENT_WAIT;
659 dcmd->mbox.w[0] = seq_num;
142extern uint8_t MR_ValidateMapInfo(struct mrsas_softc *sc);
143extern u_int16_t MR_GetLDTgtId(u_int32_t ld, MR_DRV_RAID_MAP_ALL *map);
144extern MR_LD_RAID *MR_LdRaidGet(u_int32_t ld, MR_DRV_RAID_MAP_ALL *map);
145extern void mrsas_xpt_freeze(struct mrsas_softc *sc);
146extern void mrsas_xpt_release(struct mrsas_softc *sc);
147extern MRSAS_REQUEST_DESCRIPTOR_UNION *mrsas_get_request_desc(struct mrsas_softc *sc,
148 u_int16_t index);
149extern int mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim);

--- 503 unchanged lines hidden (view full) ---

653 dcmd->cmd_status = 0x0;
654 dcmd->sge_count = 1;
655 dcmd->flags = MFI_FRAME_DIR_READ;
656 dcmd->timeout = 0;
657 dcmd->pad_0 = 0;
658 dcmd->data_xfer_len = sizeof(struct mrsas_evt_detail);
659 dcmd->opcode = MR_DCMD_CTRL_EVENT_WAIT;
660 dcmd->mbox.w[0] = seq_num;
660 sc->last_seq_num = seq_num;
661 sc->last_seq_num = seq_num;
661 dcmd->mbox.w[1] = curr_aen.word;
662 dcmd->sgl.sge32[0].phys_addr = (u_int32_t) sc->evt_detail_phys_addr;
663 dcmd->sgl.sge32[0].length = sizeof(struct mrsas_evt_detail);
664
665 if (sc->aen_cmd != NULL) {
666 mrsas_release_mfi_cmd(cmd);
667 return 0;
668 }

--- 101 unchanged lines hidden (view full) ---

770 atomic_set(&sc->fw_outstanding,0);
771
772 sc->io_cmds_highwater = 0;
773
774 /* Create a /dev entry for this device. */
775 sc->mrsas_cdev = make_dev(&mrsas_cdevsw, device_get_unit(dev), UID_ROOT,
776 GID_OPERATOR, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP), "mrsas%u",
777 device_get_unit(dev));
662 dcmd->mbox.w[1] = curr_aen.word;
663 dcmd->sgl.sge32[0].phys_addr = (u_int32_t) sc->evt_detail_phys_addr;
664 dcmd->sgl.sge32[0].length = sizeof(struct mrsas_evt_detail);
665
666 if (sc->aen_cmd != NULL) {
667 mrsas_release_mfi_cmd(cmd);
668 return 0;
669 }

--- 101 unchanged lines hidden (view full) ---

771 atomic_set(&sc->fw_outstanding,0);
772
773 sc->io_cmds_highwater = 0;
774
775 /* Create a /dev entry for this device. */
776 sc->mrsas_cdev = make_dev(&mrsas_cdevsw, device_get_unit(dev), UID_ROOT,
777 GID_OPERATOR, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP), "mrsas%u",
778 device_get_unit(dev));
779 if (device_get_unit(dev) == 0)
780 make_dev_alias(sc->mrsas_cdev, "megaraid_sas_ioctl_node");
778 if (sc->mrsas_cdev)
779 sc->mrsas_cdev->si_drv1 = sc;
780
781 sc->adprecovery = MRSAS_HBA_OPERATIONAL;
782 sc->UnevenSpanSupport = 0;
783
784 /* Initialize Firmware */
785 if (mrsas_init_fw(sc) != SUCCESS) {

--- 25 unchanged lines hidden (view full) ---

811
812 /* Initiate AEN (Asynchronous Event Notification)*/
813
814 if (mrsas_start_aen(sc)) {
815 printf("Error: start aen failed\n");
816 goto fail_start_aen;
817 }
818
781 if (sc->mrsas_cdev)
782 sc->mrsas_cdev->si_drv1 = sc;
783
784 sc->adprecovery = MRSAS_HBA_OPERATIONAL;
785 sc->UnevenSpanSupport = 0;
786
787 /* Initialize Firmware */
788 if (mrsas_init_fw(sc) != SUCCESS) {

--- 25 unchanged lines hidden (view full) ---

814
815 /* Initiate AEN (Asynchronous Event Notification)*/
816
817 if (mrsas_start_aen(sc)) {
818 printf("Error: start aen failed\n");
819 goto fail_start_aen;
820 }
821
822 /*
823 * Add this controller to mrsas_mgmt_info structure so that it
824 * can be exported to management applications
825 */
826 if (device_get_unit(dev) == 0)
827 memset(&mrsas_mgmt_info, 0, sizeof(mrsas_mgmt_info));
828
829 mrsas_mgmt_info.count++;
830 mrsas_mgmt_info.sc_ptr[mrsas_mgmt_info.max_index] = sc;
831 mrsas_mgmt_info.max_index++;
832
819 return (0);
820
821fail_start_aen:
822attach_fail_irq:
823 mrsas_teardown_intr(sc);
824attach_fail_cam:
825 mrsas_cam_detach(sc);
826attach_fail_fw:

--- 26 unchanged lines hidden (view full) ---

853 */
854static int mrsas_detach(device_t dev)
855{
856 struct mrsas_softc *sc;
857 int i = 0;
858
859 sc = device_get_softc(dev);
860 sc->remove_in_progress = 1;
833 return (0);
834
835fail_start_aen:
836attach_fail_irq:
837 mrsas_teardown_intr(sc);
838attach_fail_cam:
839 mrsas_cam_detach(sc);
840attach_fail_fw:

--- 26 unchanged lines hidden (view full) ---

867 */
868static int mrsas_detach(device_t dev)
869{
870 struct mrsas_softc *sc;
871 int i = 0;
872
873 sc = device_get_softc(dev);
874 sc->remove_in_progress = 1;
875
876 /*
877 * Take the instance off the instance array. Note that we will not
878 * decrement the max_index. We let this array be sparse array
879 */
880 for (i = 0; i < mrsas_mgmt_info.max_index; i++) {
881 if (mrsas_mgmt_info.sc_ptr[i] == sc) {
882 mrsas_mgmt_info.count--;
883 mrsas_mgmt_info.sc_ptr[i] = NULL;
884 break;
885 }
886 }
887
861 if(sc->ocr_thread_active)
862 wakeup(&sc->ocr_chan);
863 while(sc->reset_in_progress){
864 i++;
865 if (!(i % MRSAS_RESET_NOTICE_INTERVAL)) {
866 mrsas_dprint(sc, MRSAS_INFO,
867 "[%2d]waiting for ocr to be finished\n",i);
868 }

--- 227 unchanged lines hidden (view full) ---

1096 * appropriate function for processing depending on the command received.
1097 */
1098static int
1099mrsas_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, d_thread_t *td)
1100{
1101 struct mrsas_softc *sc;
1102 int ret = 0, i = 0;
1103
888 if(sc->ocr_thread_active)
889 wakeup(&sc->ocr_chan);
890 while(sc->reset_in_progress){
891 i++;
892 if (!(i % MRSAS_RESET_NOTICE_INTERVAL)) {
893 mrsas_dprint(sc, MRSAS_INFO,
894 "[%2d]waiting for ocr to be finished\n",i);
895 }

--- 227 unchanged lines hidden (view full) ---

1123 * appropriate function for processing depending on the command received.
1124 */
1125static int
1126mrsas_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, d_thread_t *td)
1127{
1128 struct mrsas_softc *sc;
1129 int ret = 0, i = 0;
1130
1104 sc = (struct mrsas_softc *)(dev->si_drv1);
1105
1131 struct mrsas_iocpacket *user_ioc = (struct mrsas_iocpacket *)arg;
1132
1133 /* get the Host number & the softc from data sent by the Application */
1134 sc = mrsas_mgmt_info.sc_ptr[user_ioc->host_no];
1135
1136 if ((mrsas_mgmt_info.max_index == user_ioc->host_no) || (sc == NULL)) {
1137 printf ("Please check the controller number\n");
1138 if (sc == NULL)
1139 printf ("There is NO such Host no. %d\n", user_ioc->host_no);
1140
1141 return ENOENT;
1142 }
1143
1106 if (sc->remove_in_progress) {
1107 mrsas_dprint(sc, MRSAS_INFO,
1108 "Driver remove or shutdown called.\n");
1109 return ENOENT;
1110 }
1111
1112 mtx_lock_spin(&sc->ioctl_lock);
1113 if (!sc->reset_in_progress) {

--- 12 unchanged lines hidden (view full) ---

1126 "OCR to be finished %d\n",i,
1127 sc->ocr_thread_active);
1128 }
1129 pause("mr_ioctl", hz);
1130 }
1131
1132do_ioctl:
1133 switch (cmd) {
1144 if (sc->remove_in_progress) {
1145 mrsas_dprint(sc, MRSAS_INFO,
1146 "Driver remove or shutdown called.\n");
1147 return ENOENT;
1148 }
1149
1150 mtx_lock_spin(&sc->ioctl_lock);
1151 if (!sc->reset_in_progress) {

--- 12 unchanged lines hidden (view full) ---

1164 "OCR to be finished %d\n",i,
1165 sc->ocr_thread_active);
1166 }
1167 pause("mr_ioctl", hz);
1168 }
1169
1170do_ioctl:
1171 switch (cmd) {
1134 case MRSAS_IOC_FIRMWARE_PASS_THROUGH:
1135 ret = mrsas_passthru(sc, (void *)arg);
1172 case MRSAS_IOC_FIRMWARE_PASS_THROUGH64:
1173#ifdef COMPAT_FREEBSD32
1174 case MRSAS_IOC_FIRMWARE_PASS_THROUGH32:
1175#endif
1176 ret = mrsas_passthru(sc, (void *)arg, cmd);
1136 break;
1137 case MRSAS_IOC_SCAN_BUS:
1138 ret = mrsas_bus_scan(sc);
1139 break;
1177 break;
1178 case MRSAS_IOC_SCAN_BUS:
1179 ret = mrsas_bus_scan(sc);
1180 break;
1181 default:
1182 mrsas_dprint(sc, MRSAS_TRACE, "IOCTL command 0x%lx is not handled\n", cmd);
1140 }
1141
1142 return (ret);
1143}
1144
1145/**
1146 * mrsas_setup_irq: Set up interrupt.
1147 * input: Adapter instance soft state

--- 2627 unchanged lines hidden ---
1183 }
1184
1185 return (ret);
1186}
1187
1188/**
1189 * mrsas_setup_irq: Set up interrupt.
1190 * input: Adapter instance soft state

--- 2627 unchanged lines hidden ---