mpt2sas-19.00.00.00_rhel6.5驱动笔记系列2-设备注册

2.2 驱动注册
   mpt2sas作为一个PCIe设备注册,注册的函数为pci_register_driver。调用的error = pci_register_driver(&scsih_driver);pci_register_driver 在linux define为__pci_register_driver。
      static struct pci_driver scsih_driver = {
      .name = MPT2SAS_DRIVER_NAME,
      .id_table = scsih_pci_table,
      .probe = _scsih_probe,
      #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
         .remove = _scsih_remove,
      #else
         .remove         = __devexit_p(_scsih_remove),
      #endif
         .shutdown = _scsih_shutdown,
         .err_handler = &_scsih_err_handler,
      #ifdef CONFIG_PM
         .suspend = _scsih_suspend,
         .resume = _scsih_resume,
      #endif
      };
   成员包含.name,.id_table,.probe,.shutdown,.suspend,.resume。
   i d_table成员变量,记录了当前这个驱动所能够进行驱动的那些设备 的ID值 ,使热插拔和模块装载系统知道什么模块对应什么硬件设备,再mpt2sas中,.id_tables由mptsas_pci_tables 这个同类型(struct pci_device_id)的结构体指针赋值。每个成员是一个一维数组,包含4部分内容{LSI VID, LSI 某个HBA的DID,subVID, subDID}.其中subVID和subDID在这里都设置为了PCI_ANY_ID,表示支持各种子类型。
2.2.1 .probe = _scsih_probe,
       PCI设备注册,int (*probe)() 指向PCI驱动程序的探测指针,当PCIe它认为驱动程序需要控制的struct pci_dev时候,就会调用该函数。在mpt2sas中,这个函数为_scsih_probe。_scsih_probe 会去找mpt2sas这个设备。首先会scsi_host_alloc初始化shost,如果初始化shost失败,就会上报找不到设备。然后通过shost_private返回ioc作为mpt2sas_adapter的指针的值,再用mmset初始化ioc指向的mpt2sas_adpter.
    ioc = shost_private(shost);
    memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
   然后继续初始化ioc intenal command的callback index。  然后对ioc中的各种lock进行spin_lock_init()初始化。对ioc中的各种链表list进行初始化/INIT_LIST_HEAD().
    初始化shost
    shost->max_cmd_len = 32;
shost->max_lun = max_lun;
shost->transportt = mpt2sas_transport_template;
shost->unique_id = ioc->id;
   调用scsi_add_host(),将mpt2sas作为host增加设 备。
   调用mpt2sas_base_attach初始化控制器
   调用_scsih_probe_devices 查找drive和raid 
   调用mpt2sas_base_start_watchdog初始化看门狗,在遇到错误的时候可以做控制器的复位
2.2.2.remove = _scsih_remove, 
       调用 mpt2sas_scsih_detach_pci将设备remove
       
2.2.3 .shutdown = _scsih_shutdown,
      设备正常掉电或者OS shut down的时候会调用_scsih_shutdown.
       对IOC传递指针,明确后续操作的对象
      调用_scsih_fw_event_cleanup_queue释放fw_event
      调用_scsih_ir_shutdown通知控制器 system shut down
      调用_scsih_ssu_to_sata_devices查询挂在控制器下的sas设备,并停止scsi io
      调用mpt2sas_base_detach remove控制器
      
2.2.4 .err_handler = &_scsih_err_handler,
     static struct pci_error_handlers _scsih_err_handler = {
.error_detected = _scsih_pci_error_detected,
.mmio_enabled = _scsih_pci_mmio_enabled,
.slot_reset = _scsih_pci_slot_reset,
.resume = _scsih_pci_resume,
};
   注册设备的错误处理机制
   调用_scsih_pci_error_detected发现控制器错误
   调用_scsih_pci_mmio_enabled Enable MMIO and dump debug registers
   调用_scsih_pci_slot_reset,调用pci_restore_state恢复PCIe配置,调用mpt2sas_base_map_resources映射IO资源设置中断,调用mpt2sas_base_hard_reset_handler进行控制器复位
       调用_scsih_pci_resume,在控制器reset之后,清除错误,恢复操作。


2.2.5 .suspend = _scsih_suspend,
   调用mpt2sas_base_stop_watchdog :stop the fault_reset_work_q
   调用_scsih_ir_shutdown 通知IR firmware system shut down
   调用_scsih_ssu_to_sata_devices,对控制器下的SATA设备下发stop 命令
       调用mpt2sas_base_free_resources,释放IO资源
       
2.2.6 .resume = _scsih_resume,
   调用mpt2sas_base_map_resources映射IO资源,设置中断

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解释脚本:#!/bin/bash #version: 0.1.0 20230510 totalstarttime=$(date +%s) # 计算间隔时间 pkg_name=`pwd |sed 's/\// /g'| awk '{print$NF}'` SWITCH_FW=${pkg_name::-8}"SIGN.fw" cd `pwd` G4XDIAG=./g4Xdiagnostics.x86_64 result_log=SR6295A_793_PCIeFW_UPDATE_`date '+%Y%m%d%H%M%S'`.log mpt_cnt=`lsmod | grep -i mpt3sas | wc -l` if [ $mpt_cnt != 0 ];then rmmod mpt3sas fi mpt3sas_driver=`ls | grep "mpt3sas-"` tar -zxvf $mpt3sas_driver cd mpt3sas/ ./compile.sh ./load.sh cd ../ echo -e "\n Switch Firmware Is Upgrading!!! \n" CNT=`$G4XDIAG -i 1 list | grep "MPI" | wc -l` echo "FW Image Is:" >> $result_log echo $SWITCH_FW | grep "SR6295A_793" >> $result_log if [ $? != 0 ]; then echo "PCIe FW Name Is Not Matched!" >> $result_log echo -e "\n FAIL: PCIe FW Name Is Not Matched! \n" exit 1 else if [ $CNT != 4 ];then echo "Lost switch!" >> $result_log $G4XDIAG -i 1 list >> $result_log echo -e "\n FAIL: Lost switch \n" exit 1 fi fi #Check platform for i in $(seq 1 1 $CNT) do hq_cmd=`$G4XDIAG -i $i cli showloc | grep "Current Switch Location" | wc -l` if [ $hq_cmd == 0 ];then echo -e "\n Platform Is Not Matched! \n" >> $result_log echo -e "\n FAIL:Platform Is Not Matched!\n" exit 1 fi done #FW upgrade for i in $(seq 1 1 $CNT) do $G4XDIAG -i $i cli showloc >> $result_log $G4XDIAG -i $i dl -f $SWITCH_FW -s >> $result_log ret=`cat $result_log | tail -n 5 | grep -i "successfully" | wc -l` if [ $ret == 1 ];then echo -e "\n Switch FW Download SUCCESS!!! \n" >> $result_log else echo -e "\n Switch FW Download FAIL!!! \n" >> $result_log echo -e "\n Switch FW Download FAIL!!! \n" exit 1 fi done echo -e "\n Upgrade PASS!!! Need restart the system to make the fresh image active! \n" totalendtime=$(date +%s) echo -e "\n Total FW update finished! Total cost time : $(( $totalendtime - $totalstarttime )) s\n" >> $result_log sleep 5 exit 0
07-11

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值