Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi

Pull SCSI misc update from James Bottomley:
"The patch contains the usual assortment of driver updates (be2iscsi,
bfa, bnx2i, fcoe, hpsa, isci, lpfc, megaraid, mpt2sas, pm8001, sg)
plus an assortment of other changes and fixes. Also new is the fact
that the isci update is delivered as a git merge (with signed tag)."

* tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: (158 commits)
isci: End the RNC resumption wait when the RNC is destroyed.
isci: Fixed RNC bug that lost the suspension or resumption during destroy
isci: Fix RNC AWAIT_SUSPENSION->INVALIDATING transition.
isci: Manage the IREQ_NO_AUTO_FREE_TAG under scic_lock.
isci: Remove obviated host callback list.
isci: Check IDEV_GONE before performing abort path operations.
isci: Restore the ATAPI device RNC management code.
isci: Don't wait for an RNC suspend if it's being destroyed.
isci: Change the phy control and link reset interface for HW reasons.
isci: Added timeouts to RNC suspensions in the abort path.
isci: Add protocol indicator for TMF requests.
isci: Directly control IREQ_ABORT_PATH_ACTIVE when completing TMFs.
isci: Wait for RNC resumption before leaving the abort path.
isci: Fix RNC suspend call for SCI_RESUMING state.
isci: Manage tag releases differently when aborting tasks.
isci: Callbacks to libsas occur under scic_lock and are synchronized.
isci: When in the abort path, defeat other resume calls until done.
isci: Implement waiting for suspend in the abort path.
isci: Make sure all TCs are terminated and cleaned in LUN reset.
isci: Manage the LLHANG timer enable/disable per-device.
...

+6566 -4323
+8
Documentation/scsi/ChangeLog.megaraid_sas
··· 1 + Release Date : Mon. Mar 19, 2012 17:00:00 PST 2012 - 2 + (emaild-id:megaraidlinux@lsi.com) 3 + Adam Radford 4 + Current Version : 00.00.06.15-rc1 5 + Old Version : 00.00.06.14-rc1 6 + 1. Optimize HostMSIxVectors setting. 7 + 2. Add fpRead/WriteCapable, fpRead/WriteAcrossStripe checks. 8 + ------------------------------------------------------------------------------- 1 9 Release Date : Fri. Jan 6, 2012 17:00:00 PST 2010 - 2 10 (emaild-id:megaraidlinux@lsi.com) 3 11 Adam Radford
+9
MAINTAINERS
··· 1599 1599 1600 1600 BROCADE BFA FC SCSI DRIVER 1601 1601 M: Jing Huang <huangj@brocade.com> 1602 + M: Krishna C Gudipati <kgudipat@brocade.com> 1602 1603 L: linux-scsi@vger.kernel.org 1603 1604 S: Supported 1604 1605 F: drivers/scsi/bfa/ ··· 6882 6881 F: Documentation/cdrom/ 6883 6882 F: drivers/cdrom/cdrom.c 6884 6883 F: include/linux/cdrom.h 6884 + 6885 + UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER 6886 + M: Vinayak Holikatti <vinholikatti@gmail.com> 6887 + M: Santosh Y <santoshsy@gmail.com> 6888 + L: linux-scsi@vger.kernel.org 6889 + S: Supported 6890 + F: Documentation/scsi/ufs.txt 6891 + F: drivers/scsi/ufs/ 6885 6892 6886 6893 UNSORTED BLOCK IMAGES (UBI) 6887 6894 M: Artem Bityutskiy <dedekind1@gmail.com>
+1
drivers/scsi/Kconfig
··· 408 408 config SCSI_HPSA 409 409 tristate "HP Smart Array SCSI driver" 410 410 depends on PCI && SCSI 411 + select CHECK_SIGNATURE 411 412 help 412 413 This driver supports HP Smart Array Controllers (circa 2009). 413 414 It is a SCSI alternative to the cciss driver, which is a block
+2
drivers/scsi/aacraid/src.c
··· 424 424 static int aac_src_ioremap(struct aac_dev *dev, u32 size) 425 425 { 426 426 if (!size) { 427 + iounmap(dev->regs.src.bar1); 428 + dev->regs.src.bar1 = NULL; 427 429 iounmap(dev->regs.src.bar0); 428 430 dev->base = dev->regs.src.bar0 = NULL; 429 431 return 0;
-4
drivers/scsi/be2iscsi/be.h
··· 132 132 ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \ 133 133 (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K)) 134 134 135 - /* Byte offset into the page corresponding to given address */ 136 - #define OFFSET_IN_PAGE(addr) \ 137 - ((size_t)(addr) & (PAGE_SIZE_4K-1)) 138 - 139 135 /* Returns bit offset within a DWORD of a bitfield */ 140 136 #define AMAP_BIT_OFFSET(_struct, field) \ 141 137 (((size_t)&(((_struct *)0)->field))%32)
+2
drivers/scsi/be2iscsi/be_cmds.c
··· 15 15 * Costa Mesa, CA 92626 16 16 */ 17 17 18 + #include <scsi/iscsi_proto.h> 19 + 18 20 #include "be.h" 19 21 #include "be_mgmt.h" 20 22 #include "be_main.h"
+130 -24
drivers/scsi/be2iscsi/be_cmds.h
··· 23 23 * firmware in the BE. These requests are communicated to the processor 24 24 * using Work Request Blocks (WRBs) submitted to the MCC-WRB ring or via one 25 25 * WRB inside a MAILBOX. 26 - * The commands are serviced by the ARM processor in the BladeEngine's MPU. 26 + * The commands are serviced by the ARM processor in the OneConnect's MPU. 27 27 */ 28 28 struct be_sge { 29 29 u32 pa_lo; ··· 163 163 #define OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES 3 164 164 #define OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG 7 165 165 #define OPCODE_COMMON_ISCSI_NTWK_SET_VLAN 14 166 - #define OPCODE_COMMON_ISCSI_NTWK_CONFIGURE_STATELESS_IP_ADDR 17 166 + #define OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR 17 167 + #define OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR 18 167 168 #define OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR 21 168 169 #define OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY 22 169 170 #define OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY 23 ··· 275 274 struct mgmt_auth_method_format auth_data; 276 275 } __packed; 277 276 278 - struct ip_address_format { 277 + struct ip_addr_format { 279 278 u16 size_of_structure; 280 279 u8 reserved; 281 280 u8 ip_type; 282 - u8 ip_address[16]; 281 + u8 addr[16]; 283 282 u32 rsvd0; 284 283 } __packed; 285 284 286 - struct mgmt_conn_info { 285 + struct mgmt_conn_info { 287 286 u32 connection_handle; 288 287 u32 connection_status; 289 288 u16 src_port; ··· 291 290 u16 dest_port_redirected; 292 291 u16 cid; 293 292 u32 estimated_throughput; 294 - struct ip_address_format src_ipaddr; 295 - struct ip_address_format dest_ipaddr; 296 - struct ip_address_format dest_ipaddr_redirected; 293 + struct ip_addr_format src_ipaddr; 294 + struct ip_addr_format dest_ipaddr; 295 + struct ip_addr_format dest_ipaddr_redirected; 297 296 struct mgmt_conn_login_options negotiated_login_options; 298 297 } __packed; 299 298 ··· 323 322 struct mgmt_conn_info conn_list[1]; 324 323 } __packed; 325 324 326 - struct be_cmd_req_get_session { 325 + struct be_cmd_get_session_req { 327 326 struct be_cmd_req_hdr hdr; 328 327 u32 session_handle; 329 328 } __packed; 330 329 331 - struct be_cmd_resp_get_session { 330 + struct be_cmd_get_session_resp { 332 331 struct be_cmd_resp_hdr hdr; 333 332 struct mgmt_session_info session_info; 334 333 } __packed; 335 334 336 335 struct mac_addr { 337 - u16 size_of_struct; 336 + u16 size_of_structure; 338 337 u8 addr[ETH_ALEN]; 339 338 } __packed; 340 339 341 - struct be_cmd_req_get_boot_target { 340 + struct be_cmd_get_boot_target_req { 342 341 struct be_cmd_req_hdr hdr; 343 342 } __packed; 344 343 345 - struct be_cmd_resp_get_boot_target { 344 + struct be_cmd_get_boot_target_resp { 346 345 struct be_cmd_resp_hdr hdr; 347 346 u32 boot_session_count; 348 347 int boot_session_handle; 349 348 }; 350 349 351 - struct be_cmd_req_mac_query { 350 + struct be_cmd_mac_query_req { 352 351 struct be_cmd_req_hdr hdr; 353 352 u8 type; 354 353 u8 permanent; 355 354 u16 if_id; 356 355 } __packed; 357 356 358 - struct be_cmd_resp_mac_query { 357 + struct be_cmd_get_mac_resp { 359 358 struct be_cmd_resp_hdr hdr; 360 359 struct mac_addr mac; 361 360 }; 361 + 362 + struct be_ip_addr_subnet_format { 363 + u16 size_of_structure; 364 + u8 ip_type; 365 + u8 ipv6_prefix_length; 366 + u8 addr[16]; 367 + u8 subnet_mask[16]; 368 + u32 rsvd0; 369 + } __packed; 370 + 371 + struct be_cmd_get_if_info_req { 372 + struct be_cmd_req_hdr hdr; 373 + u32 interface_hndl; 374 + u32 ip_type; 375 + } __packed; 376 + 377 + struct be_cmd_get_if_info_resp { 378 + struct be_cmd_req_hdr hdr; 379 + u32 interface_hndl; 380 + u32 vlan_priority; 381 + u32 ip_addr_count; 382 + u32 dhcp_state; 383 + struct be_ip_addr_subnet_format ip_addr; 384 + } __packed; 385 + 386 + struct be_ip_addr_record { 387 + u32 action; 388 + u32 interface_hndl; 389 + struct be_ip_addr_subnet_format ip_addr; 390 + u32 status; 391 + } __packed; 392 + 393 + struct be_ip_addr_record_params { 394 + u32 record_entry_count; 395 + struct be_ip_addr_record ip_record; 396 + } __packed; 397 + 398 + struct be_cmd_set_ip_addr_req { 399 + struct be_cmd_req_hdr hdr; 400 + struct be_ip_addr_record_params ip_params; 401 + } __packed; 402 + 403 + 404 + struct be_cmd_set_dhcp_req { 405 + struct be_cmd_req_hdr hdr; 406 + u32 interface_hndl; 407 + u32 ip_type; 408 + u32 flags; 409 + u32 retry_count; 410 + } __packed; 411 + 412 + struct be_cmd_rel_dhcp_req { 413 + struct be_cmd_req_hdr hdr; 414 + u32 interface_hndl; 415 + u32 ip_type; 416 + } __packed; 417 + 418 + struct be_cmd_set_def_gateway_req { 419 + struct be_cmd_req_hdr hdr; 420 + u32 action; 421 + struct ip_addr_format ip_addr; 422 + } __packed; 423 + 424 + struct be_cmd_get_def_gateway_req { 425 + struct be_cmd_req_hdr hdr; 426 + u32 ip_type; 427 + } __packed; 428 + 429 + struct be_cmd_get_def_gateway_resp { 430 + struct be_cmd_req_hdr hdr; 431 + struct ip_addr_format ip_addr; 432 + } __packed; 362 433 363 434 /******************** Create CQ ***************************/ 364 435 /** ··· 562 489 563 490 #define ETH_ALEN 6 564 491 565 - struct be_cmd_req_get_mac_addr { 492 + struct be_cmd_get_nic_conf_req { 566 493 struct be_cmd_req_hdr hdr; 567 494 u32 nic_port_count; 568 495 u32 speed; ··· 574 501 u32 rsvd[23]; 575 502 }; 576 503 577 - struct be_cmd_resp_get_mac_addr { 504 + struct be_cmd_get_nic_conf_resp { 578 505 struct be_cmd_resp_hdr hdr; 579 506 u32 nic_port_count; 580 507 u32 speed; ··· 585 512 u8 mac_address[6]; 586 513 u32 rsvd[23]; 587 514 }; 515 + 516 + #define BEISCSI_ALIAS_LEN 32 517 + 518 + struct be_cmd_hba_name { 519 + struct be_cmd_req_hdr hdr; 520 + u16 flags; 521 + u16 rsvd0; 522 + u8 initiator_name[ISCSI_NAME_LEN]; 523 + u8 initiator_alias[BEISCSI_ALIAS_LEN]; 524 + } __packed; 525 + 526 + struct be_cmd_ntwk_link_status_req { 527 + struct be_cmd_req_hdr hdr; 528 + u32 rsvd0; 529 + } __packed; 530 + 531 + /*** Port Speed Values ***/ 532 + #define BE2ISCSI_LINK_SPEED_ZERO 0x00 533 + #define BE2ISCSI_LINK_SPEED_10MBPS 0x01 534 + #define BE2ISCSI_LINK_SPEED_100MBPS 0x02 535 + #define BE2ISCSI_LINK_SPEED_1GBPS 0x03 536 + #define BE2ISCSI_LINK_SPEED_10GBPS 0x04 537 + struct be_cmd_ntwk_link_status_resp { 538 + struct be_cmd_resp_hdr hdr; 539 + u8 phys_port; 540 + u8 mac_duplex; 541 + u8 mac_speed; 542 + u8 mac_fault; 543 + u8 mgmt_mac_duplex; 544 + u8 mgmt_mac_speed; 545 + u16 qos_link_speed; 546 + u32 logical_link_speed; 547 + } __packed; 588 548 589 549 int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl, 590 550 struct be_queue_info *eq, int eq_delay); ··· 636 530 int be_poll_mcc(struct be_ctrl_info *ctrl); 637 531 int mgmt_check_supported_fw(struct be_ctrl_info *ctrl, 638 532 struct beiscsi_hba *phba); 639 - unsigned int be_cmd_get_mac_addr(struct beiscsi_hba *phba); 640 - unsigned int beiscsi_get_boot_target(struct beiscsi_hba *phba); 641 - unsigned int beiscsi_get_session_info(struct beiscsi_hba *phba, 642 - u32 boot_session_handle, 643 - struct be_dma_mem *nonemb_cmd); 533 + unsigned int be_cmd_get_initname(struct beiscsi_hba *phba); 534 + unsigned int be_cmd_get_port_speed(struct beiscsi_hba *phba); 644 535 645 536 void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag); 646 537 /*ISCSI Functuions */ ··· 818 715 819 716 struct tcp_connect_and_offload_in { 820 717 struct be_cmd_req_hdr hdr; 821 - struct ip_address_format ip_address; 718 + struct ip_addr_format ip_address; 822 719 u16 tcp_port; 823 720 u16 cid; 824 721 u16 cq_id; ··· 895 792 u32 function_caps; 896 793 } __packed; 897 794 898 - struct be_all_if_id { 795 + struct be_cmd_get_all_if_id_req { 899 796 struct be_cmd_req_hdr hdr; 900 797 u32 if_count; 901 798 u32 if_hndl_list[1]; 902 799 } __packed; 903 800 904 801 #define ISCSI_OPCODE_SCSI_DATA_OUT 5 802 + #define OPCODE_COMMON_NTWK_LINK_STATUS_QUERY 5 905 803 #define OPCODE_COMMON_MODIFY_EQ_DELAY 41 906 804 #define OPCODE_COMMON_ISCSI_CLEANUP 59 907 805 #define OPCODE_COMMON_TCP_UPLOAD 56 ··· 914 810 #define OPCODE_ISCSI_INI_DRIVER_OFFLOAD_SESSION 41 915 811 #define OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION 42 916 812 #define OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET 52 813 + #define OPCODE_COMMON_WRITE_FLASH 96 814 + #define OPCODE_COMMON_READ_FLASH 97 917 815 918 816 /* --- CMD_ISCSI_INVALIDATE_CONNECTION_TYPE --- */ 919 817 #define CMD_ISCSI_COMMAND_INVALIDATE 1
+457 -36
drivers/scsi/be2iscsi/be_iscsi.c
··· 23 23 #include <scsi/scsi_cmnd.h> 24 24 #include <scsi/scsi_device.h> 25 25 #include <scsi/scsi_host.h> 26 + #include <scsi/scsi_netlink.h> 27 + #include <net/netlink.h> 26 28 #include <scsi/scsi.h> 27 29 28 30 #include "be_iscsi.h" ··· 209 207 return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid); 210 208 } 211 209 210 + static int beiscsi_create_ipv4_iface(struct beiscsi_hba *phba) 211 + { 212 + if (phba->ipv4_iface) 213 + return 0; 214 + 215 + phba->ipv4_iface = iscsi_create_iface(phba->shost, 216 + &beiscsi_iscsi_transport, 217 + ISCSI_IFACE_TYPE_IPV4, 218 + 0, 0); 219 + if (!phba->ipv4_iface) { 220 + shost_printk(KERN_ERR, phba->shost, "Could not " 221 + "create default IPv4 address.\n"); 222 + return -ENODEV; 223 + } 224 + 225 + return 0; 226 + } 227 + 228 + static int beiscsi_create_ipv6_iface(struct beiscsi_hba *phba) 229 + { 230 + if (phba->ipv6_iface) 231 + return 0; 232 + 233 + phba->ipv6_iface = iscsi_create_iface(phba->shost, 234 + &beiscsi_iscsi_transport, 235 + ISCSI_IFACE_TYPE_IPV6, 236 + 0, 0); 237 + if (!phba->ipv6_iface) { 238 + shost_printk(KERN_ERR, phba->shost, "Could not " 239 + "create default IPv6 address.\n"); 240 + return -ENODEV; 241 + } 242 + 243 + return 0; 244 + } 245 + 246 + void beiscsi_create_def_ifaces(struct beiscsi_hba *phba) 247 + { 248 + struct be_cmd_get_if_info_resp if_info; 249 + 250 + if (!mgmt_get_if_info(phba, BE2_IPV4, &if_info)) 251 + beiscsi_create_ipv4_iface(phba); 252 + 253 + if (!mgmt_get_if_info(phba, BE2_IPV6, &if_info)) 254 + beiscsi_create_ipv6_iface(phba); 255 + } 256 + 257 + void beiscsi_destroy_def_ifaces(struct beiscsi_hba *phba) 258 + { 259 + if (phba->ipv6_iface) 260 + iscsi_destroy_iface(phba->ipv6_iface); 261 + if (phba->ipv4_iface) 262 + iscsi_destroy_iface(phba->ipv4_iface); 263 + } 264 + 265 + static int 266 + beiscsi_set_static_ip(struct Scsi_Host *shost, 267 + struct iscsi_iface_param_info *iface_param, 268 + void *data, uint32_t dt_len) 269 + { 270 + struct beiscsi_hba *phba = iscsi_host_priv(shost); 271 + struct iscsi_iface_param_info *iface_ip = NULL; 272 + struct iscsi_iface_param_info *iface_subnet = NULL; 273 + struct nlattr *nla; 274 + int ret; 275 + 276 + 277 + switch (iface_param->param) { 278 + case ISCSI_NET_PARAM_IPV4_BOOTPROTO: 279 + nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR); 280 + if (nla) 281 + iface_ip = nla_data(nla); 282 + 283 + nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET); 284 + if (nla) 285 + iface_subnet = nla_data(nla); 286 + break; 287 + case ISCSI_NET_PARAM_IPV4_ADDR: 288 + iface_ip = iface_param; 289 + nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET); 290 + if (nla) 291 + iface_subnet = nla_data(nla); 292 + break; 293 + case ISCSI_NET_PARAM_IPV4_SUBNET: 294 + iface_subnet = iface_param; 295 + nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR); 296 + if (nla) 297 + iface_ip = nla_data(nla); 298 + break; 299 + default: 300 + shost_printk(KERN_ERR, shost, "Unsupported param %d\n", 301 + iface_param->param); 302 + } 303 + 304 + if (!iface_ip || !iface_subnet) { 305 + shost_printk(KERN_ERR, shost, "IP and Subnet Mask required\n"); 306 + return -EINVAL; 307 + } 308 + 309 + ret = mgmt_set_ip(phba, iface_ip, iface_subnet, 310 + ISCSI_BOOTPROTO_STATIC); 311 + 312 + return ret; 313 + } 314 + 315 + static int 316 + beiscsi_set_ipv4(struct Scsi_Host *shost, 317 + struct iscsi_iface_param_info *iface_param, 318 + void *data, uint32_t dt_len) 319 + { 320 + struct beiscsi_hba *phba = iscsi_host_priv(shost); 321 + int ret = 0; 322 + 323 + /* Check the param */ 324 + switch (iface_param->param) { 325 + case ISCSI_NET_PARAM_IPV4_GW: 326 + ret = mgmt_set_gateway(phba, iface_param); 327 + break; 328 + case ISCSI_NET_PARAM_IPV4_BOOTPROTO: 329 + if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP) 330 + ret = mgmt_set_ip(phba, iface_param, 331 + NULL, ISCSI_BOOTPROTO_DHCP); 332 + else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC) 333 + ret = beiscsi_set_static_ip(shost, iface_param, 334 + data, dt_len); 335 + else 336 + shost_printk(KERN_ERR, shost, "Invalid BOOTPROTO: %d\n", 337 + iface_param->value[0]); 338 + break; 339 + case ISCSI_NET_PARAM_IFACE_ENABLE: 340 + if (iface_param->value[0] == ISCSI_IFACE_ENABLE) 341 + ret = beiscsi_create_ipv4_iface(phba); 342 + else 343 + iscsi_destroy_iface(phba->ipv4_iface); 344 + break; 345 + case ISCSI_NET_PARAM_IPV4_SUBNET: 346 + case ISCSI_NET_PARAM_IPV4_ADDR: 347 + ret = beiscsi_set_static_ip(shost, iface_param, 348 + data, dt_len); 349 + break; 350 + default: 351 + shost_printk(KERN_ERR, shost, "Param %d not supported\n", 352 + iface_param->param); 353 + } 354 + 355 + return ret; 356 + } 357 + 358 + static int 359 + beiscsi_set_ipv6(struct Scsi_Host *shost, 360 + struct iscsi_iface_param_info *iface_param, 361 + void *data, uint32_t dt_len) 362 + { 363 + struct beiscsi_hba *phba = iscsi_host_priv(shost); 364 + int ret = 0; 365 + 366 + switch (iface_param->param) { 367 + case ISCSI_NET_PARAM_IFACE_ENABLE: 368 + if (iface_param->value[0] == ISCSI_IFACE_ENABLE) 369 + ret = beiscsi_create_ipv6_iface(phba); 370 + else { 371 + iscsi_destroy_iface(phba->ipv6_iface); 372 + ret = 0; 373 + } 374 + break; 375 + case ISCSI_NET_PARAM_IPV6_ADDR: 376 + ret = mgmt_set_ip(phba, iface_param, NULL, 377 + ISCSI_BOOTPROTO_STATIC); 378 + break; 379 + default: 380 + shost_printk(KERN_ERR, shost, "Param %d not supported\n", 381 + iface_param->param); 382 + } 383 + 384 + return ret; 385 + } 386 + 387 + int be2iscsi_iface_set_param(struct Scsi_Host *shost, 388 + void *data, uint32_t dt_len) 389 + { 390 + struct iscsi_iface_param_info *iface_param = NULL; 391 + struct nlattr *attrib; 392 + uint32_t rm_len = dt_len; 393 + int ret = 0 ; 394 + 395 + nla_for_each_attr(attrib, data, dt_len, rm_len) { 396 + iface_param = nla_data(attrib); 397 + 398 + if (iface_param->param_type != ISCSI_NET_PARAM) 399 + continue; 400 + 401 + /* 402 + * BE2ISCSI only supports 1 interface 403 + */ 404 + if (iface_param->iface_num) { 405 + shost_printk(KERN_ERR, shost, "Invalid iface_num %d." 406 + "Only iface_num 0 is supported.\n", 407 + iface_param->iface_num); 408 + return -EINVAL; 409 + } 410 + 411 + switch (iface_param->iface_type) { 412 + case ISCSI_IFACE_TYPE_IPV4: 413 + ret = beiscsi_set_ipv4(shost, iface_param, 414 + data, dt_len); 415 + break; 416 + case ISCSI_IFACE_TYPE_IPV6: 417 + ret = beiscsi_set_ipv6(shost, iface_param, 418 + data, dt_len); 419 + break; 420 + default: 421 + shost_printk(KERN_ERR, shost, 422 + "Invalid iface type :%d passed\n", 423 + iface_param->iface_type); 424 + break; 425 + } 426 + 427 + if (ret) 428 + return ret; 429 + } 430 + 431 + return ret; 432 + } 433 + 434 + static int be2iscsi_get_if_param(struct beiscsi_hba *phba, 435 + struct iscsi_iface *iface, int param, 436 + char *buf) 437 + { 438 + struct be_cmd_get_if_info_resp if_info; 439 + int len, ip_type = BE2_IPV4; 440 + 441 + memset(&if_info, 0, sizeof(if_info)); 442 + 443 + if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) 444 + ip_type = BE2_IPV6; 445 + 446 + len = mgmt_get_if_info(phba, ip_type, &if_info); 447 + if (len) 448 + return len; 449 + 450 + switch (param) { 451 + case ISCSI_NET_PARAM_IPV4_ADDR: 452 + len = sprintf(buf, "%pI4\n", &if_info.ip_addr.addr); 453 + break; 454 + case ISCSI_NET_PARAM_IPV6_ADDR: 455 + len = sprintf(buf, "%pI6\n", &if_info.ip_addr.addr); 456 + break; 457 + case ISCSI_NET_PARAM_IPV4_BOOTPROTO: 458 + if (!if_info.dhcp_state) 459 + len = sprintf(buf, "static"); 460 + else 461 + len = sprintf(buf, "dhcp"); 462 + break; 463 + case ISCSI_NET_PARAM_IPV4_SUBNET: 464 + len = sprintf(buf, "%pI4\n", &if_info.ip_addr.subnet_mask); 465 + break; 466 + default: 467 + WARN_ON(1); 468 + } 469 + 470 + return len; 471 + } 472 + 473 + int be2iscsi_iface_get_param(struct iscsi_iface *iface, 474 + enum iscsi_param_type param_type, 475 + int param, char *buf) 476 + { 477 + struct Scsi_Host *shost = iscsi_iface_to_shost(iface); 478 + struct beiscsi_hba *phba = iscsi_host_priv(shost); 479 + struct be_cmd_get_def_gateway_resp gateway; 480 + int len = -ENOSYS; 481 + 482 + switch (param) { 483 + case ISCSI_NET_PARAM_IPV4_ADDR: 484 + case ISCSI_NET_PARAM_IPV4_SUBNET: 485 + case ISCSI_NET_PARAM_IPV4_BOOTPROTO: 486 + case ISCSI_NET_PARAM_IPV6_ADDR: 487 + len = be2iscsi_get_if_param(phba, iface, param, buf); 488 + break; 489 + case ISCSI_NET_PARAM_IFACE_ENABLE: 490 + len = sprintf(buf, "enabled"); 491 + break; 492 + case ISCSI_NET_PARAM_IPV4_GW: 493 + memset(&gateway, 0, sizeof(gateway)); 494 + len = mgmt_get_gateway(phba, BE2_IPV4, &gateway); 495 + if (!len) 496 + len = sprintf(buf, "%pI4\n", &gateway.ip_addr.addr); 497 + break; 498 + default: 499 + len = -ENOSYS; 500 + } 501 + 502 + return len; 503 + } 504 + 212 505 /** 213 506 * beiscsi_ep_get_param - get the iscsi parameter 214 507 * @ep: pointer to iscsi ep ··· 518 221 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data; 519 222 int len = 0; 520 223 521 - SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_param, param= %d\n", param); 224 + SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_get_param, param= %d\n", param); 522 225 523 226 switch (param) { 524 227 case ISCSI_PARAM_CONN_PORT: ··· 576 279 } 577 280 578 281 /** 282 + * beiscsi_get_initname - Read Initiator Name from flash 283 + * @buf: buffer bointer 284 + * @phba: The device priv structure instance 285 + * 286 + * returns number of bytes 287 + */ 288 + static int beiscsi_get_initname(char *buf, struct beiscsi_hba *phba) 289 + { 290 + int rc; 291 + unsigned int tag, wrb_num; 292 + unsigned short status, extd_status; 293 + struct be_mcc_wrb *wrb; 294 + struct be_cmd_hba_name *resp; 295 + struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; 296 + 297 + tag = be_cmd_get_initname(phba); 298 + if (!tag) { 299 + SE_DEBUG(DBG_LVL_1, "Getting Initiator Name Failed\n"); 300 + return -EBUSY; 301 + } else 302 + wait_event_interruptible(phba->ctrl.mcc_wait[tag], 303 + phba->ctrl.mcc_numtag[tag]); 304 + 305 + wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16; 306 + extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8; 307 + status = phba->ctrl.mcc_numtag[tag] & 0x000000FF; 308 + 309 + if (status || extd_status) { 310 + SE_DEBUG(DBG_LVL_1, "MailBox Command Failed with " 311 + "status = %d extd_status = %d\n", 312 + status, extd_status); 313 + free_mcc_tag(&phba->ctrl, tag); 314 + return -EAGAIN; 315 + } 316 + wrb = queue_get_wrb(mccq, wrb_num); 317 + free_mcc_tag(&phba->ctrl, tag); 318 + resp = embedded_payload(wrb); 319 + rc = sprintf(buf, "%s\n", resp->initiator_name); 320 + return rc; 321 + } 322 + 323 + /** 324 + * beiscsi_get_port_state - Get the Port State 325 + * @shost : pointer to scsi_host structure 326 + * 327 + * returns number of bytes 328 + */ 329 + static void beiscsi_get_port_state(struct Scsi_Host *shost) 330 + { 331 + struct beiscsi_hba *phba = iscsi_host_priv(shost); 332 + struct iscsi_cls_host *ihost = shost->shost_data; 333 + 334 + ihost->port_state = (phba->state == BE_ADAPTER_UP) ? 335 + ISCSI_PORT_STATE_UP : ISCSI_PORT_STATE_DOWN; 336 + } 337 + 338 + /** 339 + * beiscsi_get_port_speed - Get the Port Speed from Adapter 340 + * @shost : pointer to scsi_host structure 341 + * 342 + * returns Success/Failure 343 + */ 344 + static int beiscsi_get_port_speed(struct Scsi_Host *shost) 345 + { 346 + unsigned int tag, wrb_num; 347 + unsigned short status, extd_status; 348 + struct be_mcc_wrb *wrb; 349 + struct be_cmd_ntwk_link_status_resp *resp; 350 + struct beiscsi_hba *phba = iscsi_host_priv(shost); 351 + struct iscsi_cls_host *ihost = shost->shost_data; 352 + struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; 353 + 354 + tag = be_cmd_get_port_speed(phba); 355 + if (!tag) { 356 + SE_DEBUG(DBG_LVL_1, "Getting Port Speed Failed\n"); 357 + return -EBUSY; 358 + } else 359 + wait_event_interruptible(phba->ctrl.mcc_wait[tag], 360 + phba->ctrl.mcc_numtag[tag]); 361 + 362 + wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16; 363 + extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8; 364 + status = phba->ctrl.mcc_numtag[tag] & 0x000000FF; 365 + 366 + if (status || extd_status) { 367 + SE_DEBUG(DBG_LVL_1, "MailBox Command Failed with " 368 + "status = %d extd_status = %d\n", 369 + status, extd_status); 370 + free_mcc_tag(&phba->ctrl, tag); 371 + return -EAGAIN; 372 + } 373 + wrb = queue_get_wrb(mccq, wrb_num); 374 + free_mcc_tag(&phba->ctrl, tag); 375 + resp = embedded_payload(wrb); 376 + 377 + switch (resp->mac_speed) { 378 + case BE2ISCSI_LINK_SPEED_10MBPS: 379 + ihost->port_speed = ISCSI_PORT_SPEED_10MBPS; 380 + break; 381 + case BE2ISCSI_LINK_SPEED_100MBPS: 382 + ihost->port_speed = BE2ISCSI_LINK_SPEED_100MBPS; 383 + break; 384 + case BE2ISCSI_LINK_SPEED_1GBPS: 385 + ihost->port_speed = ISCSI_PORT_SPEED_1GBPS; 386 + break; 387 + case BE2ISCSI_LINK_SPEED_10GBPS: 388 + ihost->port_speed = ISCSI_PORT_SPEED_10GBPS; 389 + break; 390 + default: 391 + ihost->port_speed = ISCSI_PORT_SPEED_UNKNOWN; 392 + } 393 + return 0; 394 + } 395 + 396 + /** 579 397 * beiscsi_get_host_param - get the iscsi parameter 580 398 * @shost: pointer to scsi_host structure 581 399 * @param: parameter type identifier ··· 713 301 return status; 714 302 } 715 303 break; 304 + case ISCSI_HOST_PARAM_INITIATOR_NAME: 305 + status = beiscsi_get_initname(buf, phba); 306 + if (status < 0) { 307 + SE_DEBUG(DBG_LVL_1, 308 + "Retreiving Initiator Name Failed\n"); 309 + return status; 310 + } 311 + break; 312 + case ISCSI_HOST_PARAM_PORT_STATE: 313 + beiscsi_get_port_state(shost); 314 + status = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost)); 315 + break; 316 + case ISCSI_HOST_PARAM_PORT_SPEED: 317 + status = beiscsi_get_port_speed(shost); 318 + if (status) { 319 + SE_DEBUG(DBG_LVL_1, 320 + "Retreiving Port Speed Failed\n"); 321 + return status; 322 + } 323 + status = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost)); 324 + break; 716 325 default: 717 326 return iscsi_host_get_param(shost, param, buf); 718 327 } ··· 742 309 743 310 int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba) 744 311 { 745 - struct be_cmd_resp_get_mac_addr *resp; 746 - struct be_mcc_wrb *wrb; 747 - unsigned int tag, wrb_num; 748 - unsigned short status, extd_status; 749 - struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; 312 + struct be_cmd_get_nic_conf_resp resp; 750 313 int rc; 751 314 752 - if (phba->read_mac_address) 753 - return sysfs_format_mac(buf, phba->mac_address, 754 - ETH_ALEN); 315 + if (strlen(phba->mac_address)) 316 + return strlcpy(buf, phba->mac_address, PAGE_SIZE); 755 317 756 - tag = be_cmd_get_mac_addr(phba); 757 - if (!tag) { 758 - SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n"); 759 - return -EBUSY; 760 - } else 761 - wait_event_interruptible(phba->ctrl.mcc_wait[tag], 762 - phba->ctrl.mcc_numtag[tag]); 318 + memset(&resp, 0, sizeof(resp)); 319 + rc = mgmt_get_nic_conf(phba, &resp); 320 + if (rc) 321 + return rc; 763 322 764 - wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16; 765 - extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8; 766 - status = phba->ctrl.mcc_numtag[tag] & 0x000000FF; 767 - if (status || extd_status) { 768 - SE_DEBUG(DBG_LVL_1, "Failed to get be_cmd_get_mac_addr" 769 - " status = %d extd_status = %d\n", 770 - status, extd_status); 771 - free_mcc_tag(&phba->ctrl, tag); 772 - return -EAGAIN; 773 - } 774 - wrb = queue_get_wrb(mccq, wrb_num); 775 - free_mcc_tag(&phba->ctrl, tag); 776 - resp = embedded_payload(wrb); 777 - memcpy(phba->mac_address, resp->mac_address, ETH_ALEN); 778 - rc = sysfs_format_mac(buf, phba->mac_address, 779 - ETH_ALEN); 780 - phba->read_mac_address = 1; 781 - return rc; 323 + memcpy(phba->mac_address, resp.mac_address, ETH_ALEN); 324 + return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN); 782 325 } 783 - 784 326 785 327 /** 786 328 * beiscsi_conn_get_stats - get the iscsi stats ··· 1144 736 umode_t be2iscsi_attr_is_visible(int param_type, int param) 1145 737 { 1146 738 switch (param_type) { 739 + case ISCSI_NET_PARAM: 740 + switch (param) { 741 + case ISCSI_NET_PARAM_IFACE_ENABLE: 742 + case ISCSI_NET_PARAM_IPV4_ADDR: 743 + case ISCSI_NET_PARAM_IPV4_SUBNET: 744 + case ISCSI_NET_PARAM_IPV4_BOOTPROTO: 745 + case ISCSI_NET_PARAM_IPV4_GW: 746 + case ISCSI_NET_PARAM_IPV6_ADDR: 747 + return S_IRUGO; 748 + default: 749 + return 0; 750 + } 1147 751 case ISCSI_HOST_PARAM: 1148 752 switch (param) { 1149 753 case ISCSI_HOST_PARAM_HWADDRESS: 1150 - case ISCSI_HOST_PARAM_IPADDRESS: 1151 754 case ISCSI_HOST_PARAM_INITIATOR_NAME: 755 + case ISCSI_HOST_PARAM_PORT_STATE: 756 + case ISCSI_HOST_PARAM_PORT_SPEED: 1152 757 return S_IRUGO; 1153 758 default: 1154 759 return 0;
+15
drivers/scsi/be2iscsi/be_iscsi.h
··· 25 25 26 26 #define BE2_IPV4 0x1 27 27 #define BE2_IPV6 0x10 28 + #define BE2_DHCP_V4 0x05 29 + 30 + #define NON_BLOCKING 0x0 31 + #define BLOCKING 0x1 32 + 33 + void beiscsi_create_def_ifaces(struct beiscsi_hba *phba); 34 + 35 + void beiscsi_destroy_def_ifaces(struct beiscsi_hba *phba); 36 + 37 + int be2iscsi_iface_get_param(struct iscsi_iface *iface, 38 + enum iscsi_param_type param_type, 39 + int param, char *buf); 40 + 41 + int be2iscsi_iface_set_param(struct Scsi_Host *shost, 42 + void *data, uint32_t count); 28 43 29 44 umode_t be2iscsi_attr_is_visible(int param_type, int param); 30 45
+269 -180
drivers/scsi/be2iscsi/be_main.c
··· 28 28 #include <linux/semaphore.h> 29 29 #include <linux/iscsi_boot_sysfs.h> 30 30 #include <linux/module.h> 31 + #include <linux/bsg-lib.h> 31 32 32 33 #include <scsi/libiscsi.h> 34 + #include <scsi/scsi_bsg_iscsi.h> 35 + #include <scsi/scsi_netlink.h> 33 36 #include <scsi/scsi_transport_iscsi.h> 34 37 #include <scsi/scsi_transport.h> 35 38 #include <scsi/scsi_cmnd.h> ··· 51 48 52 49 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); 53 50 MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR); 54 - MODULE_AUTHOR("ServerEngines Corporation"); 51 + MODULE_VERSION(BUILD_STR); 52 + MODULE_AUTHOR("Emulex Corporation"); 55 53 MODULE_LICENSE("GPL"); 56 54 module_param(be_iopoll_budget, int, 0); 57 55 module_param(enable_msix, int, 0); ··· 151 147 struct invalidate_command_table *inv_tbl; 152 148 struct be_dma_mem nonemb_cmd; 153 149 unsigned int cid, tag, i, num_invalidate; 154 - int rc = FAILED; 155 150 156 151 /* invalidate iocbs */ 157 152 cls_session = starget_to_session(scsi_target(sc->device)); 158 153 session = cls_session->dd_data; 159 154 spin_lock_bh(&session->lock); 160 - if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) 161 - goto unlock; 162 - 155 + if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) { 156 + spin_unlock_bh(&session->lock); 157 + return FAILED; 158 + } 163 159 conn = session->leadconn; 164 160 beiscsi_conn = conn->dd_data; 165 161 phba = beiscsi_conn->phba; ··· 212 208 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, 213 209 nonemb_cmd.va, nonemb_cmd.dma); 214 210 return iscsi_eh_device_reset(sc); 215 - unlock: 216 - spin_unlock_bh(&session->lock); 217 - return rc; 218 211 } 219 212 220 213 static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf) ··· 231 230 case ISCSI_BOOT_TGT_IP_ADDR: 232 231 if (boot_conn->dest_ipaddr.ip_type == 0x1) 233 232 rc = sprintf(buf, "%pI4\n", 234 - (char *)&boot_conn->dest_ipaddr.ip_address); 233 + (char *)&boot_conn->dest_ipaddr.addr); 235 234 else 236 235 rc = sprintf(str, "%pI6\n", 237 - (char *)&boot_conn->dest_ipaddr.ip_address); 236 + (char *)&boot_conn->dest_ipaddr.addr); 238 237 break; 239 238 case ISCSI_BOOT_TGT_PORT: 240 239 rc = sprintf(str, "%d\n", boot_conn->dest_port); ··· 312 311 rc = sprintf(str, "0\n"); 313 312 break; 314 313 case ISCSI_BOOT_ETH_MAC: 315 - rc = beiscsi_get_macaddr(buf, phba); 316 - if (rc < 0) { 317 - SE_DEBUG(DBG_LVL_1, "beiscsi_get_macaddr Failed\n"); 318 - return rc; 319 - } 320 - break; 314 + rc = beiscsi_get_macaddr(str, phba); 315 + break; 321 316 default: 322 317 rc = -ENOSYS; 323 318 break; ··· 391 394 392 395 static struct scsi_host_template beiscsi_sht = { 393 396 .module = THIS_MODULE, 394 - .name = "ServerEngines 10Gbe open-iscsi Initiator Driver", 397 + .name = "Emulex 10Gbe open-iscsi Initiator Driver", 395 398 .proc_name = DRV_NAME, 396 399 .queuecommand = iscsi_queuecommand, 397 400 .change_queue_depth = iscsi_change_queue_depth, ··· 406 409 .max_sectors = BEISCSI_MAX_SECTORS, 407 410 .cmd_per_lun = BEISCSI_CMD_PER_LUN, 408 411 .use_clustering = ENABLE_CLUSTERING, 412 + .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, 413 + 409 414 }; 410 415 411 416 static struct scsi_transport_template *beiscsi_scsi_transport; ··· 434 435 phba->shost = shost; 435 436 phba->pcidev = pci_dev_get(pcidev); 436 437 pci_set_drvdata(pcidev, phba); 438 + phba->interface_handle = 0xFFFFFFFF; 437 439 438 440 if (iscsi_host_add(shost, &phba->pcidev->dev)) 439 441 goto free_devices; ··· 544 544 &mbox_mem_alloc->dma); 545 545 if (!mbox_mem_alloc->va) { 546 546 beiscsi_unmap_pci_function(phba); 547 - status = -ENOMEM; 548 - return status; 547 + return -ENOMEM; 549 548 } 550 549 551 550 mbox_mem_align->size = sizeof(struct be_mcc_mailbox); ··· 1251 1252 task = pwrb_handle->pio_handle; 1252 1253 1253 1254 io_task = task->dd_data; 1254 - spin_lock(&phba->mgmt_sgl_lock); 1255 + spin_lock_bh(&phba->mgmt_sgl_lock); 1255 1256 free_mgmt_sgl_handle(phba, io_task->psgl_handle); 1256 - spin_unlock(&phba->mgmt_sgl_lock); 1257 + spin_unlock_bh(&phba->mgmt_sgl_lock); 1257 1258 spin_lock_bh(&session->lock); 1258 1259 free_wrb_handle(phba, pwrb_context, pwrb_handle); 1259 1260 spin_unlock_bh(&session->lock); ··· 1369 1370 struct be_bus_address phys_addr; 1370 1371 struct list_head *pbusy_list; 1371 1372 struct async_pdu_handle *pasync_handle = NULL; 1372 - int buffer_len = 0; 1373 - unsigned char buffer_index = -1; 1374 1373 unsigned char is_header = 0; 1375 1374 1376 1375 phys_addr.u.a32.address_lo = ··· 1389 1392 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 1, 1390 1393 (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, 1391 1394 index) / 32] & PDUCQE_INDEX_MASK)); 1392 - 1393 - buffer_len = (unsigned int)(phys_addr.u.a64.address - 1394 - pasync_ctx->async_header.pa_base.u.a64.address); 1395 - 1396 - buffer_index = buffer_len / 1397 - pasync_ctx->async_header.buffer_size; 1398 - 1399 1395 break; 1400 1396 case UNSOL_DATA_NOTIFY: 1401 1397 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 0, (pdpdu_cqe-> 1402 1398 dw[offsetof(struct amap_i_t_dpdu_cqe, 1403 1399 index) / 32] & PDUCQE_INDEX_MASK)); 1404 - buffer_len = (unsigned long)(phys_addr.u.a64.address - 1405 - pasync_ctx->async_data.pa_base.u. 1406 - a64.address); 1407 - buffer_index = buffer_len / pasync_ctx->async_data.buffer_size; 1408 1400 break; 1409 1401 default: 1410 1402 pbusy_list = NULL; ··· 1404 1418 return NULL; 1405 1419 } 1406 1420 1407 - WARN_ON(!(buffer_index <= pasync_ctx->async_data.num_entries)); 1408 1421 WARN_ON(list_empty(pbusy_list)); 1409 1422 list_for_each_entry(pasync_handle, pbusy_list, link) { 1410 - WARN_ON(pasync_handle->consumed); 1411 - if (pasync_handle->index == buffer_index) 1423 + if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address) 1412 1424 break; 1413 1425 } 1414 1426 ··· 1433 1449 unsigned int num_entries, writables = 0; 1434 1450 unsigned int *pep_read_ptr, *pwritables; 1435 1451 1436 - 1452 + num_entries = pasync_ctx->num_entries; 1437 1453 if (is_header) { 1438 1454 pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr; 1439 1455 pwritables = &pasync_ctx->async_header.writables; 1440 - num_entries = pasync_ctx->async_header.num_entries; 1441 1456 } else { 1442 1457 pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr; 1443 1458 pwritables = &pasync_ctx->async_data.writables; 1444 - num_entries = pasync_ctx->async_data.num_entries; 1445 1459 } 1446 1460 1447 1461 while ((*pep_read_ptr) != cq_index) { ··· 1473 1491 return 0; 1474 1492 } 1475 1493 1476 - static unsigned int hwi_free_async_msg(struct beiscsi_hba *phba, 1494 + static void hwi_free_async_msg(struct beiscsi_hba *phba, 1477 1495 unsigned int cri) 1478 1496 { 1479 1497 struct hwi_controller *phwi_ctrlr; 1480 1498 struct hwi_async_pdu_context *pasync_ctx; 1481 1499 struct async_pdu_handle *pasync_handle, *tmp_handle; 1482 1500 struct list_head *plist; 1483 - unsigned int i = 0; 1484 1501 1485 1502 phwi_ctrlr = phba->phwi_ctrlr; 1486 1503 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr); ··· 1489 1508 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) { 1490 1509 list_del(&pasync_handle->link); 1491 1510 1492 - if (i == 0) { 1511 + if (pasync_handle->is_header) { 1493 1512 list_add_tail(&pasync_handle->link, 1494 1513 &pasync_ctx->async_header.free_list); 1495 1514 pasync_ctx->async_header.free_entries++; 1496 - i++; 1497 1515 } else { 1498 1516 list_add_tail(&pasync_handle->link, 1499 1517 &pasync_ctx->async_data.free_list); 1500 1518 pasync_ctx->async_data.free_entries++; 1501 - i++; 1502 1519 } 1503 1520 } 1504 1521 1505 1522 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list); 1506 1523 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0; 1507 1524 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0; 1508 - return 0; 1509 1525 } 1510 1526 1511 1527 static struct phys_addr * ··· 1535 1557 1536 1558 phwi_ctrlr = phba->phwi_ctrlr; 1537 1559 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr); 1560 + num_entries = pasync_ctx->num_entries; 1538 1561 1539 1562 if (is_header) { 1540 - num_entries = pasync_ctx->async_header.num_entries; 1541 1563 writables = min(pasync_ctx->async_header.writables, 1542 1564 pasync_ctx->async_header.free_entries); 1543 1565 pfree_link = pasync_ctx->async_header.free_list.next; 1544 1566 host_write_num = pasync_ctx->async_header.host_write_ptr; 1545 1567 ring_id = phwi_ctrlr->default_pdu_hdr.id; 1546 1568 } else { 1547 - num_entries = pasync_ctx->async_data.num_entries; 1548 1569 writables = min(pasync_ctx->async_data.writables, 1549 1570 pasync_ctx->async_data.free_entries); 1550 1571 pfree_link = pasync_ctx->async_data.free_list.next; ··· 1650 1673 } 1651 1674 memcpy(pfirst_buffer + offset, 1652 1675 pasync_handle->pbuffer, buf_len); 1653 - offset = buf_len; 1676 + offset += buf_len; 1654 1677 } 1655 1678 index++; 1656 1679 } ··· 1659 1682 (beiscsi_conn->beiscsi_conn_cid - 1660 1683 phba->fw_config.iscsi_cid_start), 1661 1684 phdr, hdr_len, pfirst_buffer, 1662 - buf_len); 1685 + offset); 1663 1686 1664 - if (status == 0) 1665 - hwi_free_async_msg(phba, cri); 1687 + hwi_free_async_msg(phba, cri); 1666 1688 return 0; 1667 1689 } 1668 1690 ··· 2205 2229 struct mem_array *mem_arr, *mem_arr_orig; 2206 2230 unsigned int i, j, alloc_size, curr_alloc_size; 2207 2231 2208 - phba->phwi_ctrlr = kmalloc(phba->params.hwi_ws_sz, GFP_KERNEL); 2232 + phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL); 2209 2233 if (!phba->phwi_ctrlr) 2210 2234 return -ENOMEM; 2211 2235 ··· 2325 2349 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0); 2326 2350 } 2327 2351 2328 - static void beiscsi_init_wrb_handle(struct beiscsi_hba *phba) 2352 + static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba) 2329 2353 { 2330 2354 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb; 2331 - struct wrb_handle *pwrb_handle; 2355 + struct wrb_handle *pwrb_handle = NULL; 2332 2356 struct hwi_controller *phwi_ctrlr; 2333 2357 struct hwi_wrb_context *pwrb_context; 2334 - struct iscsi_wrb *pwrb; 2335 - unsigned int num_cxn_wrbh; 2336 - unsigned int num_cxn_wrb, j, idx, index; 2358 + struct iscsi_wrb *pwrb = NULL; 2359 + unsigned int num_cxn_wrbh = 0; 2360 + unsigned int num_cxn_wrb = 0, j, idx = 0, index; 2337 2361 2338 2362 mem_descr_wrbh = phba->init_mem; 2339 2363 mem_descr_wrbh += HWI_MEM_WRBH; 2340 2364 2341 2365 mem_descr_wrb = phba->init_mem; 2342 2366 mem_descr_wrb += HWI_MEM_WRB; 2343 - 2344 - idx = 0; 2345 - pwrb_handle = mem_descr_wrbh->mem_array[idx].virtual_address; 2346 - num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) / 2347 - ((sizeof(struct wrb_handle)) * 2348 - phba->params.wrbs_per_cxn)); 2349 2367 phwi_ctrlr = phba->phwi_ctrlr; 2350 2368 2351 2369 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) { ··· 2347 2377 pwrb_context->pwrb_handle_base = 2348 2378 kzalloc(sizeof(struct wrb_handle *) * 2349 2379 phba->params.wrbs_per_cxn, GFP_KERNEL); 2380 + if (!pwrb_context->pwrb_handle_base) { 2381 + shost_printk(KERN_ERR, phba->shost, 2382 + "Mem Alloc Failed. Failing to load\n"); 2383 + goto init_wrb_hndl_failed; 2384 + } 2350 2385 pwrb_context->pwrb_handle_basestd = 2351 2386 kzalloc(sizeof(struct wrb_handle *) * 2352 2387 phba->params.wrbs_per_cxn, GFP_KERNEL); 2388 + if (!pwrb_context->pwrb_handle_basestd) { 2389 + shost_printk(KERN_ERR, phba->shost, 2390 + "Mem Alloc Failed. Failing to load\n"); 2391 + goto init_wrb_hndl_failed; 2392 + } 2393 + if (!num_cxn_wrbh) { 2394 + pwrb_handle = 2395 + mem_descr_wrbh->mem_array[idx].virtual_address; 2396 + num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) / 2397 + ((sizeof(struct wrb_handle)) * 2398 + phba->params.wrbs_per_cxn)); 2399 + idx++; 2400 + } 2401 + pwrb_context->alloc_index = 0; 2402 + pwrb_context->wrb_handles_available = 0; 2403 + pwrb_context->free_index = 0; 2404 + 2353 2405 if (num_cxn_wrbh) { 2354 - pwrb_context->alloc_index = 0; 2355 - pwrb_context->wrb_handles_available = 0; 2356 2406 for (j = 0; j < phba->params.wrbs_per_cxn; j++) { 2357 2407 pwrb_context->pwrb_handle_base[j] = pwrb_handle; 2358 2408 pwrb_context->pwrb_handle_basestd[j] = ··· 2381 2391 pwrb_handle->wrb_index = j; 2382 2392 pwrb_handle++; 2383 2393 } 2384 - pwrb_context->free_index = 0; 2385 - num_cxn_wrbh--; 2386 - } else { 2387 - idx++; 2388 - pwrb_handle = 2389 - mem_descr_wrbh->mem_array[idx].virtual_address; 2390 - num_cxn_wrbh = 2391 - ((mem_descr_wrbh->mem_array[idx].size) / 2392 - ((sizeof(struct wrb_handle)) * 2393 - phba->params.wrbs_per_cxn)); 2394 - pwrb_context->alloc_index = 0; 2395 - for (j = 0; j < phba->params.wrbs_per_cxn; j++) { 2396 - pwrb_context->pwrb_handle_base[j] = pwrb_handle; 2397 - pwrb_context->pwrb_handle_basestd[j] = 2398 - pwrb_handle; 2399 - pwrb_context->wrb_handles_available++; 2400 - pwrb_handle->wrb_index = j; 2401 - pwrb_handle++; 2402 - } 2403 - pwrb_context->free_index = 0; 2404 2394 num_cxn_wrbh--; 2405 2395 } 2406 2396 } 2407 2397 idx = 0; 2408 - pwrb = mem_descr_wrb->mem_array[idx].virtual_address; 2409 - num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) / 2410 - ((sizeof(struct iscsi_wrb) * 2411 - phba->params.wrbs_per_cxn)); 2412 2398 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) { 2413 2399 pwrb_context = &phwi_ctrlr->wrb_context[index]; 2400 + if (!num_cxn_wrb) { 2401 + pwrb = mem_descr_wrb->mem_array[idx].virtual_address; 2402 + num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) / 2403 + ((sizeof(struct iscsi_wrb) * 2404 + phba->params.wrbs_per_cxn)); 2405 + idx++; 2406 + } 2407 + 2414 2408 if (num_cxn_wrb) { 2415 2409 for (j = 0; j < phba->params.wrbs_per_cxn; j++) { 2416 2410 pwrb_handle = pwrb_context->pwrb_handle_base[j]; ··· 2402 2428 pwrb++; 2403 2429 } 2404 2430 num_cxn_wrb--; 2405 - } else { 2406 - idx++; 2407 - pwrb = mem_descr_wrb->mem_array[idx].virtual_address; 2408 - num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) / 2409 - ((sizeof(struct iscsi_wrb) * 2410 - phba->params.wrbs_per_cxn)); 2411 - for (j = 0; j < phba->params.wrbs_per_cxn; j++) { 2412 - pwrb_handle = pwrb_context->pwrb_handle_base[j]; 2413 - pwrb_handle->pwrb = pwrb; 2414 - pwrb++; 2415 - } 2416 - num_cxn_wrb--; 2417 2431 } 2418 2432 } 2433 + return 0; 2434 + init_wrb_hndl_failed: 2435 + for (j = index; j > 0; j--) { 2436 + pwrb_context = &phwi_ctrlr->wrb_context[j]; 2437 + kfree(pwrb_context->pwrb_handle_base); 2438 + kfree(pwrb_context->pwrb_handle_basestd); 2439 + } 2440 + return -ENOMEM; 2419 2441 } 2420 2442 2421 2443 static void hwi_init_async_pdu_ctx(struct beiscsi_hba *phba) ··· 2420 2450 struct hba_parameters *p = &phba->params; 2421 2451 struct hwi_async_pdu_context *pasync_ctx; 2422 2452 struct async_pdu_handle *pasync_header_h, *pasync_data_h; 2423 - unsigned int index; 2453 + unsigned int index, idx, num_per_mem, num_async_data; 2424 2454 struct be_mem_descriptor *mem_descr; 2425 2455 2426 2456 mem_descr = (struct be_mem_descriptor *)phba->init_mem; ··· 2432 2462 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx; 2433 2463 memset(pasync_ctx, 0, sizeof(*pasync_ctx)); 2434 2464 2435 - pasync_ctx->async_header.num_entries = p->asyncpdus_per_ctrl; 2436 - pasync_ctx->async_header.buffer_size = p->defpdu_hdr_sz; 2437 - pasync_ctx->async_data.buffer_size = p->defpdu_data_sz; 2438 - pasync_ctx->async_data.num_entries = p->asyncpdus_per_ctrl; 2465 + pasync_ctx->num_entries = p->asyncpdus_per_ctrl; 2466 + pasync_ctx->buffer_size = p->defpdu_hdr_sz; 2439 2467 2440 2468 mem_descr = (struct be_mem_descriptor *)phba->init_mem; 2441 2469 mem_descr += HWI_MEM_ASYNC_HEADER_BUF; ··· 2478 2510 pasync_ctx->async_header.writables = 0; 2479 2511 INIT_LIST_HEAD(&pasync_ctx->async_header.free_list); 2480 2512 2481 - mem_descr = (struct be_mem_descriptor *)phba->init_mem; 2482 - mem_descr += HWI_MEM_ASYNC_DATA_BUF; 2483 - if (mem_descr->mem_array[0].virtual_address) { 2484 - SE_DEBUG(DBG_LVL_8, 2485 - "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_BUF" 2486 - "va=%p\n", mem_descr->mem_array[0].virtual_address); 2487 - } else 2488 - shost_printk(KERN_WARNING, phba->shost, 2489 - "No Virtual address\n"); 2490 - pasync_ctx->async_data.va_base = 2491 - mem_descr->mem_array[0].virtual_address; 2492 - pasync_ctx->async_data.pa_base.u.a64.address = 2493 - mem_descr->mem_array[0].bus_address.u.a64.address; 2494 2513 2495 2514 mem_descr = (struct be_mem_descriptor *)phba->init_mem; 2496 2515 mem_descr += HWI_MEM_ASYNC_DATA_RING; ··· 2508 2553 pasync_data_h = 2509 2554 (struct async_pdu_handle *)pasync_ctx->async_data.handle_base; 2510 2555 2556 + mem_descr = (struct be_mem_descriptor *)phba->init_mem; 2557 + mem_descr += HWI_MEM_ASYNC_DATA_BUF; 2558 + if (mem_descr->mem_array[0].virtual_address) { 2559 + SE_DEBUG(DBG_LVL_8, 2560 + "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_BUF" 2561 + "va=%p\n", mem_descr->mem_array[0].virtual_address); 2562 + } else 2563 + shost_printk(KERN_WARNING, phba->shost, 2564 + "No Virtual address\n"); 2565 + idx = 0; 2566 + pasync_ctx->async_data.va_base = 2567 + mem_descr->mem_array[idx].virtual_address; 2568 + pasync_ctx->async_data.pa_base.u.a64.address = 2569 + mem_descr->mem_array[idx].bus_address.u.a64.address; 2570 + 2571 + num_async_data = ((mem_descr->mem_array[idx].size) / 2572 + phba->params.defpdu_data_sz); 2573 + num_per_mem = 0; 2574 + 2511 2575 for (index = 0; index < p->asyncpdus_per_ctrl; index++) { 2512 2576 pasync_header_h->cri = -1; 2513 2577 pasync_header_h->index = (char)index; ··· 2552 2578 pasync_data_h->cri = -1; 2553 2579 pasync_data_h->index = (char)index; 2554 2580 INIT_LIST_HEAD(&pasync_data_h->link); 2581 + 2582 + if (!num_async_data) { 2583 + num_per_mem = 0; 2584 + idx++; 2585 + pasync_ctx->async_data.va_base = 2586 + mem_descr->mem_array[idx].virtual_address; 2587 + pasync_ctx->async_data.pa_base.u.a64.address = 2588 + mem_descr->mem_array[idx]. 2589 + bus_address.u.a64.address; 2590 + 2591 + num_async_data = ((mem_descr->mem_array[idx].size) / 2592 + phba->params.defpdu_data_sz); 2593 + } 2555 2594 pasync_data_h->pbuffer = 2556 2595 (void *)((unsigned long) 2557 2596 (pasync_ctx->async_data.va_base) + 2558 - (p->defpdu_data_sz * index)); 2597 + (p->defpdu_data_sz * num_per_mem)); 2559 2598 2560 2599 pasync_data_h->pa.u.a64.address = 2561 2600 pasync_ctx->async_data.pa_base.u.a64.address + 2562 - (p->defpdu_data_sz * index); 2601 + (p->defpdu_data_sz * num_per_mem); 2602 + num_per_mem++; 2603 + num_async_data--; 2563 2604 2564 2605 list_add_tail(&pasync_data_h->link, 2565 2606 &pasync_ctx->async_data.free_list); ··· 2902 2913 static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q) 2903 2914 { 2904 2915 struct be_dma_mem *mem = &q->dma_mem; 2905 - if (mem->va) 2916 + if (mem->va) { 2906 2917 pci_free_consistent(phba->pcidev, mem->size, 2907 2918 mem->va, mem->dma); 2919 + mem->va = NULL; 2920 + } 2908 2921 } 2909 2922 2910 2923 static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q, ··· 3206 3215 error: 3207 3216 shost_printk(KERN_ERR, phba->shost, "hwi_init_port failed"); 3208 3217 hwi_cleanup(phba); 3209 - return -ENOMEM; 3218 + return status; 3210 3219 } 3211 3220 3212 3221 static int hwi_init_controller(struct beiscsi_hba *phba) ··· 3227 3236 } 3228 3237 3229 3238 iscsi_init_global_templates(phba); 3230 - beiscsi_init_wrb_handle(phba); 3239 + if (beiscsi_init_wrb_handle(phba)) 3240 + return -ENOMEM; 3241 + 3231 3242 hwi_init_async_pdu_ctx(phba); 3232 3243 if (hwi_init_port(phba) != 0) { 3233 3244 shost_printk(KERN_ERR, phba->shost, ··· 3281 3288 3282 3289 free_init: 3283 3290 beiscsi_free_mem(phba); 3284 - return -ENOMEM; 3291 + return ret; 3285 3292 } 3286 3293 3287 3294 static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba) ··· 3468 3475 3469 3476 static int beiscsi_get_boot_info(struct beiscsi_hba *phba) 3470 3477 { 3471 - struct be_cmd_resp_get_boot_target *boot_resp; 3472 - struct be_cmd_resp_get_session *session_resp; 3478 + struct be_cmd_get_boot_target_resp *boot_resp; 3479 + struct be_cmd_get_session_resp *session_resp; 3473 3480 struct be_mcc_wrb *wrb; 3474 3481 struct be_dma_mem nonemb_cmd; 3475 3482 unsigned int tag, wrb_num; ··· 3477 3484 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; 3478 3485 int ret = -ENOMEM; 3479 3486 3480 - tag = beiscsi_get_boot_target(phba); 3487 + tag = mgmt_get_boot_target(phba); 3481 3488 if (!tag) { 3482 - SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n"); 3489 + SE_DEBUG(DBG_LVL_1, "beiscsi_get_boot_info Failed\n"); 3483 3490 return -EAGAIN; 3484 3491 } else 3485 3492 wait_event_interruptible(phba->ctrl.mcc_wait[tag], ··· 3489 3496 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8; 3490 3497 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF; 3491 3498 if (status || extd_status) { 3492 - SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed" 3499 + SE_DEBUG(DBG_LVL_1, "beiscsi_get_boot_info Failed" 3493 3500 " status = %d extd_status = %d\n", 3494 3501 status, extd_status); 3495 3502 free_mcc_tag(&phba->ctrl, tag); ··· 3515 3522 } 3516 3523 3517 3524 memset(nonemb_cmd.va, 0, sizeof(*session_resp)); 3518 - tag = beiscsi_get_session_info(phba, 3519 - boot_resp->boot_session_handle, &nonemb_cmd); 3525 + tag = mgmt_get_session_info(phba, boot_resp->boot_session_handle, 3526 + &nonemb_cmd); 3520 3527 if (!tag) { 3521 3528 SE_DEBUG(DBG_LVL_1, "beiscsi_get_session_info" 3522 3529 " Failed\n"); ··· 3689 3696 kfree(phba->ep_array); 3690 3697 } 3691 3698 3699 + static void beiscsi_cleanup_task(struct iscsi_task *task) 3700 + { 3701 + struct beiscsi_io_task *io_task = task->dd_data; 3702 + struct iscsi_conn *conn = task->conn; 3703 + struct beiscsi_conn *beiscsi_conn = conn->dd_data; 3704 + struct beiscsi_hba *phba = beiscsi_conn->phba; 3705 + struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; 3706 + struct hwi_wrb_context *pwrb_context; 3707 + struct hwi_controller *phwi_ctrlr; 3708 + 3709 + phwi_ctrlr = phba->phwi_ctrlr; 3710 + pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid 3711 + - phba->fw_config.iscsi_cid_start]; 3712 + 3713 + if (io_task->cmd_bhs) { 3714 + pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, 3715 + io_task->bhs_pa.u.a64.address); 3716 + io_task->cmd_bhs = NULL; 3717 + } 3718 + 3719 + if (task->sc) { 3720 + if (io_task->pwrb_handle) { 3721 + free_wrb_handle(phba, pwrb_context, 3722 + io_task->pwrb_handle); 3723 + io_task->pwrb_handle = NULL; 3724 + } 3725 + 3726 + if (io_task->psgl_handle) { 3727 + spin_lock(&phba->io_sgl_lock); 3728 + free_io_sgl_handle(phba, io_task->psgl_handle); 3729 + spin_unlock(&phba->io_sgl_lock); 3730 + io_task->psgl_handle = NULL; 3731 + } 3732 + } else { 3733 + if (!beiscsi_conn->login_in_progress) { 3734 + if (io_task->pwrb_handle) { 3735 + free_wrb_handle(phba, pwrb_context, 3736 + io_task->pwrb_handle); 3737 + io_task->pwrb_handle = NULL; 3738 + } 3739 + if (io_task->psgl_handle) { 3740 + spin_lock(&phba->mgmt_sgl_lock); 3741 + free_mgmt_sgl_handle(phba, 3742 + io_task->psgl_handle); 3743 + spin_unlock(&phba->mgmt_sgl_lock); 3744 + io_task->psgl_handle = NULL; 3745 + } 3746 + } 3747 + } 3748 + } 3749 + 3692 3750 void 3693 3751 beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn, 3694 3752 struct beiscsi_offload_params *params) ··· 3748 3704 struct iscsi_target_context_update_wrb *pwrb = NULL; 3749 3705 struct be_mem_descriptor *mem_descr; 3750 3706 struct beiscsi_hba *phba = beiscsi_conn->phba; 3707 + struct iscsi_task *task = beiscsi_conn->task; 3708 + struct iscsi_session *session = task->conn->session; 3751 3709 u32 doorbell = 0; 3752 3710 3753 3711 /* 3754 3712 * We can always use 0 here because it is reserved by libiscsi for 3755 3713 * login/startup related tasks. 3756 3714 */ 3715 + beiscsi_conn->login_in_progress = 0; 3716 + spin_lock_bh(&session->lock); 3717 + beiscsi_cleanup_task(task); 3718 + spin_unlock_bh(&session->lock); 3719 + 3757 3720 pwrb_handle = alloc_wrb_handle(phba, (beiscsi_conn->beiscsi_conn_cid - 3758 3721 phba->fw_config.iscsi_cid_start)); 3759 3722 pwrb = (struct iscsi_target_context_update_wrb *)pwrb_handle->pwrb; ··· 3874 3823 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr; 3875 3824 task->hdr_max = sizeof(struct be_cmd_bhs); 3876 3825 io_task->psgl_handle = NULL; 3877 - io_task->psgl_handle = NULL; 3826 + io_task->pwrb_handle = NULL; 3878 3827 3879 3828 if (task->sc) { 3880 3829 spin_lock(&phba->io_sgl_lock); ··· 3916 3865 io_task->pwrb_handle = 3917 3866 beiscsi_conn->plogin_wrb_handle; 3918 3867 } 3868 + beiscsi_conn->task = task; 3919 3869 } else { 3920 3870 spin_lock(&phba->mgmt_sgl_lock); 3921 3871 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba); ··· 3959 3907 io_task->pwrb_handle = NULL; 3960 3908 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, 3961 3909 io_task->bhs_pa.u.a64.address); 3910 + io_task->cmd_bhs = NULL; 3962 3911 SE_DEBUG(DBG_LVL_1, "Alloc of SGL_ICD Failed\n"); 3963 3912 return -ENOMEM; 3964 - } 3965 - 3966 - static void beiscsi_cleanup_task(struct iscsi_task *task) 3967 - { 3968 - struct beiscsi_io_task *io_task = task->dd_data; 3969 - struct iscsi_conn *conn = task->conn; 3970 - struct beiscsi_conn *beiscsi_conn = conn->dd_data; 3971 - struct beiscsi_hba *phba = beiscsi_conn->phba; 3972 - struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; 3973 - struct hwi_wrb_context *pwrb_context; 3974 - struct hwi_controller *phwi_ctrlr; 3975 - 3976 - phwi_ctrlr = phba->phwi_ctrlr; 3977 - pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid 3978 - - phba->fw_config.iscsi_cid_start]; 3979 - if (io_task->pwrb_handle) { 3980 - free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); 3981 - io_task->pwrb_handle = NULL; 3982 - } 3983 - 3984 - if (io_task->cmd_bhs) { 3985 - pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, 3986 - io_task->bhs_pa.u.a64.address); 3987 - } 3988 - 3989 - if (task->sc) { 3990 - if (io_task->psgl_handle) { 3991 - spin_lock(&phba->io_sgl_lock); 3992 - free_io_sgl_handle(phba, io_task->psgl_handle); 3993 - spin_unlock(&phba->io_sgl_lock); 3994 - io_task->psgl_handle = NULL; 3995 - } 3996 - } else { 3997 - if (task->hdr && 3998 - ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN)) 3999 - return; 4000 - if (io_task->psgl_handle) { 4001 - spin_lock(&phba->mgmt_sgl_lock); 4002 - free_mgmt_sgl_handle(phba, io_task->psgl_handle); 4003 - spin_unlock(&phba->mgmt_sgl_lock); 4004 - io_task->psgl_handle = NULL; 4005 - } 4006 - } 4007 3913 } 4008 3914 4009 3915 static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg, ··· 4003 3993 &io_task->cmd_bhs->iscsi_hdr.lun, sizeof(struct scsi_lun)); 4004 3994 4005 3995 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb, 4006 - cpu_to_be16(*(unsigned short *)&io_task->cmd_bhs->iscsi_hdr.lun)); 3996 + cpu_to_be16(*(unsigned short *) 3997 + &io_task->cmd_bhs->iscsi_hdr.lun)); 4007 3998 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen); 4008 3999 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, 4009 4000 io_task->pwrb_handle->wrb_index); ··· 4137 4126 return beiscsi_iotask(task, sg, num_sg, xferlen, writedir); 4138 4127 } 4139 4128 4129 + /** 4130 + * beiscsi_bsg_request - handle bsg request from ISCSI transport 4131 + * @job: job to handle 4132 + */ 4133 + static int beiscsi_bsg_request(struct bsg_job *job) 4134 + { 4135 + struct Scsi_Host *shost; 4136 + struct beiscsi_hba *phba; 4137 + struct iscsi_bsg_request *bsg_req = job->request; 4138 + int rc = -EINVAL; 4139 + unsigned int tag; 4140 + struct be_dma_mem nonemb_cmd; 4141 + struct be_cmd_resp_hdr *resp; 4142 + struct iscsi_bsg_reply *bsg_reply = job->reply; 4143 + unsigned short status, extd_status; 4144 + 4145 + shost = iscsi_job_to_shost(job); 4146 + phba = iscsi_host_priv(shost); 4147 + 4148 + switch (bsg_req->msgcode) { 4149 + case ISCSI_BSG_HST_VENDOR: 4150 + nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, 4151 + job->request_payload.payload_len, 4152 + &nonemb_cmd.dma); 4153 + if (nonemb_cmd.va == NULL) { 4154 + SE_DEBUG(DBG_LVL_1, "Failed to allocate memory for " 4155 + "beiscsi_bsg_request\n"); 4156 + return -EIO; 4157 + } 4158 + tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job, 4159 + &nonemb_cmd); 4160 + if (!tag) { 4161 + SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n"); 4162 + pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, 4163 + nonemb_cmd.va, nonemb_cmd.dma); 4164 + return -EAGAIN; 4165 + } else 4166 + wait_event_interruptible(phba->ctrl.mcc_wait[tag], 4167 + phba->ctrl.mcc_numtag[tag]); 4168 + extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8; 4169 + status = phba->ctrl.mcc_numtag[tag] & 0x000000FF; 4170 + free_mcc_tag(&phba->ctrl, tag); 4171 + resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va; 4172 + sg_copy_from_buffer(job->reply_payload.sg_list, 4173 + job->reply_payload.sg_cnt, 4174 + nonemb_cmd.va, (resp->response_length 4175 + + sizeof(*resp))); 4176 + bsg_reply->reply_payload_rcv_len = resp->response_length; 4177 + bsg_reply->result = status; 4178 + bsg_job_done(job, bsg_reply->result, 4179 + bsg_reply->reply_payload_rcv_len); 4180 + pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, 4181 + nonemb_cmd.va, nonemb_cmd.dma); 4182 + if (status || extd_status) { 4183 + SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed" 4184 + " status = %d extd_status = %d\n", 4185 + status, extd_status); 4186 + return -EIO; 4187 + } 4188 + break; 4189 + 4190 + default: 4191 + SE_DEBUG(DBG_LVL_1, "Unsupported bsg command: 0x%x\n", 4192 + bsg_req->msgcode); 4193 + break; 4194 + } 4195 + 4196 + return rc; 4197 + } 4198 + 4140 4199 static void beiscsi_quiesce(struct beiscsi_hba *phba) 4141 4200 { 4142 4201 struct hwi_controller *phwi_ctrlr; ··· 4264 4183 return; 4265 4184 } 4266 4185 4186 + beiscsi_destroy_def_ifaces(phba); 4267 4187 beiscsi_quiesce(phba); 4268 4188 iscsi_boot_destroy_kset(phba->boot_kset); 4269 4189 iscsi_host_remove(phba->shost); ··· 4349 4267 phba->num_cpus = num_cpus; 4350 4268 SE_DEBUG(DBG_LVL_8, "num_cpus = %d\n", phba->num_cpus); 4351 4269 4352 - if (enable_msix) 4270 + if (enable_msix) { 4353 4271 beiscsi_msix_enable(phba); 4272 + if (!phba->msix_enabled) 4273 + phba->num_cpus = 1; 4274 + } 4354 4275 ret = be_ctrl_init(phba, pcidev); 4355 4276 if (ret) { 4356 4277 shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-" ··· 4451 4366 * iscsi boot. 4452 4367 */ 4453 4368 shost_printk(KERN_ERR, phba->shost, "Could not set up " 4454 - "iSCSI boot info."); 4369 + "iSCSI boot info.\n"); 4455 4370 4371 + beiscsi_create_def_ifaces(phba); 4456 4372 SE_DEBUG(DBG_LVL_8, "\n\n\n SUCCESS - DRIVER LOADED\n\n\n"); 4457 4373 return 0; 4458 4374 ··· 4504 4418 .bind_conn = beiscsi_conn_bind, 4505 4419 .destroy_conn = iscsi_conn_teardown, 4506 4420 .attr_is_visible = be2iscsi_attr_is_visible, 4421 + .set_iface_param = be2iscsi_iface_set_param, 4422 + .get_iface_param = be2iscsi_iface_get_param, 4507 4423 .set_param = beiscsi_set_param, 4508 4424 .get_conn_param = iscsi_conn_get_param, 4509 4425 .get_session_param = iscsi_session_get_param, ··· 4523 4435 .ep_poll = beiscsi_ep_poll, 4524 4436 .ep_disconnect = beiscsi_ep_disconnect, 4525 4437 .session_recovery_timedout = iscsi_session_recovery_timedout, 4438 + .bsg_request = beiscsi_bsg_request, 4526 4439 }; 4527 4440 4528 4441 static struct pci_driver beiscsi_pci_driver = {
+9 -8
drivers/scsi/be2iscsi/be_main.h
··· 34 34 35 35 #include "be.h" 36 36 #define DRV_NAME "be2iscsi" 37 - #define BUILD_STR "4.1.239.0" 38 - #define BE_NAME "ServerEngines BladeEngine2" \ 39 - "Linux iSCSI Driver version" BUILD_STR 37 + #define BUILD_STR "4.2.162.0" 38 + #define BE_NAME "Emulex OneConnect" \ 39 + "Open-iSCSI Driver version" BUILD_STR 40 40 #define DRV_DESC BE_NAME " " "Driver" 41 41 42 42 #define BE_VENDOR_ID 0x19A2 ··· 316 316 struct iscsi_endpoint **ep_array; 317 317 struct iscsi_boot_kset *boot_kset; 318 318 struct Scsi_Host *shost; 319 + struct iscsi_iface *ipv4_iface; 320 + struct iscsi_iface *ipv6_iface; 319 321 struct { 320 322 /** 321 323 * group together since they are used most frequently ··· 347 345 struct work_struct work_cqs; /* The work being queued */ 348 346 struct be_ctrl_info ctrl; 349 347 unsigned int generation; 350 - unsigned int read_mac_address; 348 + unsigned int interface_handle; 351 349 struct mgmt_session_info boot_sess; 352 350 struct invalidate_command_table inv_tbl[128]; 353 351 ··· 527 525 528 526 unsigned int free_entries; 529 527 unsigned int busy_entries; 530 - unsigned int buffer_size; 531 - unsigned int num_entries; 532 528 533 529 struct list_head free_list; 534 530 } async_header; ··· 543 543 544 544 unsigned int free_entries; 545 545 unsigned int busy_entries; 546 - unsigned int buffer_size; 547 546 struct list_head free_list; 548 - unsigned int num_entries; 549 547 } async_data; 548 + 549 + unsigned int buffer_size; 550 + unsigned int num_entries; 550 551 551 552 /** 552 553 * This is a varying size list! Do not add anything
+501 -23
drivers/scsi/be2iscsi/be_mgmt.c
··· 17 17 * Costa Mesa, CA 92626 18 18 */ 19 19 20 + #include <linux/bsg-lib.h> 21 + #include <scsi/scsi_transport_iscsi.h> 22 + #include <scsi/scsi_bsg_iscsi.h> 20 23 #include "be_mgmt.h" 21 24 #include "be_iscsi.h" 22 - #include <scsi/scsi_transport_iscsi.h> 23 25 24 - unsigned int beiscsi_get_boot_target(struct beiscsi_hba *phba) 26 + unsigned int mgmt_get_boot_target(struct beiscsi_hba *phba) 25 27 { 26 28 struct be_ctrl_info *ctrl = &phba->ctrl; 27 29 struct be_mcc_wrb *wrb; 28 - struct be_cmd_req_get_mac_addr *req; 30 + struct be_cmd_get_boot_target_req *req; 29 31 unsigned int tag = 0; 30 32 31 33 SE_DEBUG(DBG_LVL_8, "In bescsi_get_boot_target\n"); ··· 44 42 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 45 43 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, 46 44 OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET, 47 - sizeof(*req)); 45 + sizeof(struct be_cmd_get_boot_target_resp)); 48 46 49 47 be_mcc_notify(phba); 50 48 spin_unlock(&ctrl->mbox_lock); 51 49 return tag; 52 50 } 53 51 54 - unsigned int beiscsi_get_session_info(struct beiscsi_hba *phba, 55 - u32 boot_session_handle, 56 - struct be_dma_mem *nonemb_cmd) 52 + unsigned int mgmt_get_session_info(struct beiscsi_hba *phba, 53 + u32 boot_session_handle, 54 + struct be_dma_mem *nonemb_cmd) 57 55 { 58 56 struct be_ctrl_info *ctrl = &phba->ctrl; 59 57 struct be_mcc_wrb *wrb; 60 58 unsigned int tag = 0; 61 - struct be_cmd_req_get_session *req; 62 - struct be_cmd_resp_get_session *resp; 59 + struct be_cmd_get_session_req *req; 60 + struct be_cmd_get_session_resp *resp; 63 61 struct be_sge *sge; 64 62 65 63 SE_DEBUG(DBG_LVL_8, "In beiscsi_get_session_info\n"); ··· 187 185 nonemb_cmd.va, nonemb_cmd.dma); 188 186 189 187 return status; 188 + } 189 + 190 + unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl, 191 + struct beiscsi_hba *phba, 192 + struct bsg_job *job, 193 + struct be_dma_mem *nonemb_cmd) 194 + { 195 + struct be_cmd_resp_hdr *resp; 196 + struct be_mcc_wrb *wrb = wrb_from_mccq(phba); 197 + struct be_sge *mcc_sge = nonembedded_sgl(wrb); 198 + unsigned int tag = 0; 199 + struct iscsi_bsg_request *bsg_req = job->request; 200 + struct be_bsg_vendor_cmd *req = nonemb_cmd->va; 201 + unsigned short region, sector_size, sector, offset; 202 + 203 + nonemb_cmd->size = job->request_payload.payload_len; 204 + memset(nonemb_cmd->va, 0, nonemb_cmd->size); 205 + resp = nonemb_cmd->va; 206 + region = bsg_req->rqst_data.h_vendor.vendor_cmd[1]; 207 + sector_size = bsg_req->rqst_data.h_vendor.vendor_cmd[2]; 208 + sector = bsg_req->rqst_data.h_vendor.vendor_cmd[3]; 209 + offset = bsg_req->rqst_data.h_vendor.vendor_cmd[4]; 210 + req->region = region; 211 + req->sector = sector; 212 + req->offset = offset; 213 + spin_lock(&ctrl->mbox_lock); 214 + memset(wrb, 0, sizeof(*wrb)); 215 + 216 + switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) { 217 + case BEISCSI_WRITE_FLASH: 218 + offset = sector * sector_size + offset; 219 + be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 220 + OPCODE_COMMON_WRITE_FLASH, sizeof(*req)); 221 + sg_copy_to_buffer(job->request_payload.sg_list, 222 + job->request_payload.sg_cnt, 223 + nonemb_cmd->va + offset, job->request_len); 224 + break; 225 + case BEISCSI_READ_FLASH: 226 + be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 227 + OPCODE_COMMON_READ_FLASH, sizeof(*req)); 228 + break; 229 + default: 230 + shost_printk(KERN_WARNING, phba->shost, 231 + "Unsupported cmd = 0x%x\n\n", bsg_req->rqst_data. 232 + h_vendor.vendor_cmd[0]); 233 + spin_unlock(&ctrl->mbox_lock); 234 + return -ENOSYS; 235 + } 236 + 237 + tag = alloc_mcc_tag(phba); 238 + if (!tag) { 239 + spin_unlock(&ctrl->mbox_lock); 240 + return tag; 241 + } 242 + 243 + be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 244 + job->request_payload.sg_cnt); 245 + mcc_sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); 246 + mcc_sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); 247 + mcc_sge->len = cpu_to_le32(nonemb_cmd->size); 248 + wrb->tag0 |= tag; 249 + 250 + be_mcc_notify(phba); 251 + 252 + spin_unlock(&ctrl->mbox_lock); 253 + return tag; 190 254 } 191 255 192 256 int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute) ··· 396 328 struct sockaddr *dst_addr, 397 329 struct beiscsi_endpoint *beiscsi_ep, 398 330 struct be_dma_mem *nonemb_cmd) 399 - 400 331 { 401 332 struct hwi_controller *phwi_ctrlr; 402 333 struct hwi_context_memory *phwi_context; ··· 441 374 if (dst_addr->sa_family == PF_INET) { 442 375 __be32 s_addr = daddr_in->sin_addr.s_addr; 443 376 req->ip_address.ip_type = BE2_IPV4; 444 - req->ip_address.ip_address[0] = s_addr & 0x000000ff; 445 - req->ip_address.ip_address[1] = (s_addr & 0x0000ff00) >> 8; 446 - req->ip_address.ip_address[2] = (s_addr & 0x00ff0000) >> 16; 447 - req->ip_address.ip_address[3] = (s_addr & 0xff000000) >> 24; 377 + req->ip_address.addr[0] = s_addr & 0x000000ff; 378 + req->ip_address.addr[1] = (s_addr & 0x0000ff00) >> 8; 379 + req->ip_address.addr[2] = (s_addr & 0x00ff0000) >> 16; 380 + req->ip_address.addr[3] = (s_addr & 0xff000000) >> 24; 448 381 req->tcp_port = ntohs(daddr_in->sin_port); 449 382 beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr; 450 383 beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port); 451 384 beiscsi_ep->ip_type = BE2_IPV4; 452 385 } else if (dst_addr->sa_family == PF_INET6) { 453 386 req->ip_address.ip_type = BE2_IPV6; 454 - memcpy(&req->ip_address.ip_address, 387 + memcpy(&req->ip_address.addr, 455 388 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16); 456 389 req->tcp_port = ntohs(daddr_in6->sin6_port); 457 390 beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port); ··· 486 419 return tag; 487 420 } 488 421 489 - unsigned int be_cmd_get_mac_addr(struct beiscsi_hba *phba) 422 + unsigned int mgmt_get_all_if_id(struct beiscsi_hba *phba) 490 423 { 491 424 struct be_ctrl_info *ctrl = &phba->ctrl; 492 - struct be_mcc_wrb *wrb; 493 - struct be_cmd_req_get_mac_addr *req; 494 - unsigned int tag = 0; 425 + struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); 426 + struct be_cmd_get_all_if_id_req *req = embedded_payload(wrb); 427 + struct be_cmd_get_all_if_id_req *pbe_allid = req; 428 + int status = 0; 495 429 496 - SE_DEBUG(DBG_LVL_8, "In be_cmd_get_mac_addr\n"); 430 + memset(wrb, 0, sizeof(*wrb)); 431 + 432 + spin_lock(&ctrl->mbox_lock); 433 + 434 + be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 435 + be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 436 + OPCODE_COMMON_ISCSI_NTWK_GET_ALL_IF_ID, 437 + sizeof(*req)); 438 + status = be_mbox_notify(ctrl); 439 + if (!status) 440 + phba->interface_handle = pbe_allid->if_hndl_list[0]; 441 + else { 442 + shost_printk(KERN_WARNING, phba->shost, 443 + "Failed in mgmt_get_all_if_id\n"); 444 + } 445 + spin_unlock(&ctrl->mbox_lock); 446 + 447 + return status; 448 + } 449 + 450 + static int mgmt_exec_nonemb_cmd(struct beiscsi_hba *phba, 451 + struct be_dma_mem *nonemb_cmd, void *resp_buf, 452 + int resp_buf_len) 453 + { 454 + struct be_ctrl_info *ctrl = &phba->ctrl; 455 + struct be_mcc_wrb *wrb = wrb_from_mccq(phba); 456 + unsigned short status, extd_status; 457 + struct be_sge *sge; 458 + unsigned int tag; 459 + int rc = 0; 460 + 461 + spin_lock(&ctrl->mbox_lock); 462 + tag = alloc_mcc_tag(phba); 463 + if (!tag) { 464 + spin_unlock(&ctrl->mbox_lock); 465 + rc = -ENOMEM; 466 + goto free_cmd; 467 + } 468 + memset(wrb, 0, sizeof(*wrb)); 469 + wrb->tag0 |= tag; 470 + sge = nonembedded_sgl(wrb); 471 + 472 + be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1); 473 + sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); 474 + sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); 475 + sge->len = cpu_to_le32(nonemb_cmd->size); 476 + 477 + be_mcc_notify(phba); 478 + spin_unlock(&ctrl->mbox_lock); 479 + 480 + wait_event_interruptible(phba->ctrl.mcc_wait[tag], 481 + phba->ctrl.mcc_numtag[tag]); 482 + 483 + extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8; 484 + status = phba->ctrl.mcc_numtag[tag] & 0x000000FF; 485 + if (status || extd_status) { 486 + SE_DEBUG(DBG_LVL_1, 487 + "mgmt_exec_nonemb_cmd Failed status = %d" 488 + "extd_status = %d\n", status, extd_status); 489 + rc = -EIO; 490 + goto free_tag; 491 + } 492 + 493 + if (resp_buf) 494 + memcpy(resp_buf, nonemb_cmd->va, resp_buf_len); 495 + 496 + free_tag: 497 + free_mcc_tag(&phba->ctrl, tag); 498 + free_cmd: 499 + pci_free_consistent(ctrl->pdev, nonemb_cmd->size, 500 + nonemb_cmd->va, nonemb_cmd->dma); 501 + return rc; 502 + } 503 + 504 + static int mgmt_alloc_cmd_data(struct beiscsi_hba *phba, struct be_dma_mem *cmd, 505 + int iscsi_cmd, int size) 506 + { 507 + cmd->va = pci_alloc_consistent(phba->ctrl.pdev, sizeof(size), 508 + &cmd->dma); 509 + if (!cmd->va) { 510 + SE_DEBUG(DBG_LVL_1, "Failed to allocate memory for if info\n"); 511 + return -ENOMEM; 512 + } 513 + memset(cmd->va, 0, sizeof(size)); 514 + cmd->size = size; 515 + be_cmd_hdr_prepare(cmd->va, CMD_SUBSYSTEM_ISCSI, iscsi_cmd, size); 516 + return 0; 517 + } 518 + 519 + static int 520 + mgmt_static_ip_modify(struct beiscsi_hba *phba, 521 + struct be_cmd_get_if_info_resp *if_info, 522 + struct iscsi_iface_param_info *ip_param, 523 + struct iscsi_iface_param_info *subnet_param, 524 + uint32_t ip_action) 525 + { 526 + struct be_cmd_set_ip_addr_req *req; 527 + struct be_dma_mem nonemb_cmd; 528 + uint32_t ip_type; 529 + int rc; 530 + 531 + rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd, 532 + OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR, 533 + sizeof(*req)); 534 + if (rc) 535 + return rc; 536 + 537 + ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ? 538 + BE2_IPV6 : BE2_IPV4 ; 539 + 540 + req = nonemb_cmd.va; 541 + req->ip_params.record_entry_count = 1; 542 + req->ip_params.ip_record.action = ip_action; 543 + req->ip_params.ip_record.interface_hndl = 544 + phba->interface_handle; 545 + req->ip_params.ip_record.ip_addr.size_of_structure = 546 + sizeof(struct be_ip_addr_subnet_format); 547 + req->ip_params.ip_record.ip_addr.ip_type = ip_type; 548 + 549 + if (ip_action == IP_ACTION_ADD) { 550 + memcpy(req->ip_params.ip_record.ip_addr.addr, ip_param->value, 551 + ip_param->len); 552 + 553 + if (subnet_param) 554 + memcpy(req->ip_params.ip_record.ip_addr.subnet_mask, 555 + subnet_param->value, subnet_param->len); 556 + } else { 557 + memcpy(req->ip_params.ip_record.ip_addr.addr, 558 + if_info->ip_addr.addr, ip_param->len); 559 + 560 + memcpy(req->ip_params.ip_record.ip_addr.subnet_mask, 561 + if_info->ip_addr.subnet_mask, ip_param->len); 562 + } 563 + 564 + rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0); 565 + if (rc < 0) 566 + shost_printk(KERN_WARNING, phba->shost, 567 + "Failed to Modify existing IP Address\n"); 568 + return rc; 569 + } 570 + 571 + static int mgmt_modify_gateway(struct beiscsi_hba *phba, uint8_t *gt_addr, 572 + uint32_t gtway_action, uint32_t param_len) 573 + { 574 + struct be_cmd_set_def_gateway_req *req; 575 + struct be_dma_mem nonemb_cmd; 576 + int rt_val; 577 + 578 + 579 + rt_val = mgmt_alloc_cmd_data(phba, &nonemb_cmd, 580 + OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY, 581 + sizeof(*req)); 582 + if (rt_val) 583 + return rt_val; 584 + 585 + req = nonemb_cmd.va; 586 + req->action = gtway_action; 587 + req->ip_addr.ip_type = BE2_IPV4; 588 + 589 + memcpy(req->ip_addr.addr, gt_addr, param_len); 590 + 591 + return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0); 592 + } 593 + 594 + int mgmt_set_ip(struct beiscsi_hba *phba, 595 + struct iscsi_iface_param_info *ip_param, 596 + struct iscsi_iface_param_info *subnet_param, 597 + uint32_t boot_proto) 598 + { 599 + struct be_cmd_get_def_gateway_resp gtway_addr_set; 600 + struct be_cmd_get_if_info_resp if_info; 601 + struct be_cmd_set_dhcp_req *dhcpreq; 602 + struct be_cmd_rel_dhcp_req *reldhcp; 603 + struct be_dma_mem nonemb_cmd; 604 + uint8_t *gtway_addr; 605 + uint32_t ip_type; 606 + int rc; 607 + 608 + if (mgmt_get_all_if_id(phba)) 609 + return -EIO; 610 + 611 + memset(&if_info, 0, sizeof(if_info)); 612 + ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ? 613 + BE2_IPV6 : BE2_IPV4 ; 614 + 615 + rc = mgmt_get_if_info(phba, ip_type, &if_info); 616 + if (rc) 617 + return rc; 618 + 619 + if (boot_proto == ISCSI_BOOTPROTO_DHCP) { 620 + if (if_info.dhcp_state) { 621 + shost_printk(KERN_WARNING, phba->shost, 622 + "DHCP Already Enabled\n"); 623 + return 0; 624 + } 625 + /* The ip_param->len is 1 in DHCP case. Setting 626 + proper IP len as this it is used while 627 + freeing the Static IP. 628 + */ 629 + ip_param->len = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ? 630 + IP_V6_LEN : IP_V4_LEN; 631 + 632 + } else { 633 + if (if_info.dhcp_state) { 634 + 635 + memset(&if_info, 0, sizeof(if_info)); 636 + rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd, 637 + OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR, 638 + sizeof(*reldhcp)); 639 + 640 + if (rc) 641 + return rc; 642 + 643 + reldhcp = nonemb_cmd.va; 644 + reldhcp->interface_hndl = phba->interface_handle; 645 + reldhcp->ip_type = ip_type; 646 + 647 + rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0); 648 + if (rc < 0) { 649 + shost_printk(KERN_WARNING, phba->shost, 650 + "Failed to Delete existing dhcp\n"); 651 + return rc; 652 + } 653 + } 654 + } 655 + 656 + /* Delete the Static IP Set */ 657 + if (if_info.ip_addr.addr[0]) { 658 + rc = mgmt_static_ip_modify(phba, &if_info, ip_param, NULL, 659 + IP_ACTION_DEL); 660 + if (rc) 661 + return rc; 662 + } 663 + 664 + /* Delete the Gateway settings if mode change is to DHCP */ 665 + if (boot_proto == ISCSI_BOOTPROTO_DHCP) { 666 + memset(&gtway_addr_set, 0, sizeof(gtway_addr_set)); 667 + rc = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set); 668 + if (rc) { 669 + shost_printk(KERN_WARNING, phba->shost, 670 + "Failed to Get Gateway Addr\n"); 671 + return rc; 672 + } 673 + 674 + if (gtway_addr_set.ip_addr.addr[0]) { 675 + gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr; 676 + rc = mgmt_modify_gateway(phba, gtway_addr, 677 + IP_ACTION_DEL, IP_V4_LEN); 678 + 679 + if (rc) { 680 + shost_printk(KERN_WARNING, phba->shost, 681 + "Failed to clear Gateway Addr Set\n"); 682 + return rc; 683 + } 684 + } 685 + } 686 + 687 + /* Set Adapter to DHCP/Static Mode */ 688 + if (boot_proto == ISCSI_BOOTPROTO_DHCP) { 689 + rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd, 690 + OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR, 691 + sizeof(*dhcpreq)); 692 + if (rc) 693 + return rc; 694 + 695 + dhcpreq = nonemb_cmd.va; 696 + dhcpreq->flags = BLOCKING; 697 + dhcpreq->retry_count = 1; 698 + dhcpreq->interface_hndl = phba->interface_handle; 699 + dhcpreq->ip_type = BE2_DHCP_V4; 700 + 701 + return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0); 702 + } else { 703 + return mgmt_static_ip_modify(phba, &if_info, ip_param, 704 + subnet_param, IP_ACTION_ADD); 705 + } 706 + 707 + return rc; 708 + } 709 + 710 + int mgmt_set_gateway(struct beiscsi_hba *phba, 711 + struct iscsi_iface_param_info *gateway_param) 712 + { 713 + struct be_cmd_get_def_gateway_resp gtway_addr_set; 714 + uint8_t *gtway_addr; 715 + int rt_val; 716 + 717 + memset(&gtway_addr_set, 0, sizeof(gtway_addr_set)); 718 + rt_val = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set); 719 + if (rt_val) { 720 + shost_printk(KERN_WARNING, phba->shost, 721 + "Failed to Get Gateway Addr\n"); 722 + return rt_val; 723 + } 724 + 725 + if (gtway_addr_set.ip_addr.addr[0]) { 726 + gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr; 727 + rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_DEL, 728 + gateway_param->len); 729 + if (rt_val) { 730 + shost_printk(KERN_WARNING, phba->shost, 731 + "Failed to clear Gateway Addr Set\n"); 732 + return rt_val; 733 + } 734 + } 735 + 736 + gtway_addr = (uint8_t *)&gateway_param->value; 737 + rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_ADD, 738 + gateway_param->len); 739 + 740 + if (rt_val) 741 + shost_printk(KERN_WARNING, phba->shost, 742 + "Failed to Set Gateway Addr\n"); 743 + 744 + return rt_val; 745 + } 746 + 747 + int mgmt_get_gateway(struct beiscsi_hba *phba, int ip_type, 748 + struct be_cmd_get_def_gateway_resp *gateway) 749 + { 750 + struct be_cmd_get_def_gateway_req *req; 751 + struct be_dma_mem nonemb_cmd; 752 + int rc; 753 + 754 + rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd, 755 + OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY, 756 + sizeof(*gateway)); 757 + if (rc) 758 + return rc; 759 + 760 + req = nonemb_cmd.va; 761 + req->ip_type = ip_type; 762 + 763 + return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, gateway, 764 + sizeof(*gateway)); 765 + } 766 + 767 + int mgmt_get_if_info(struct beiscsi_hba *phba, int ip_type, 768 + struct be_cmd_get_if_info_resp *if_info) 769 + { 770 + struct be_cmd_get_if_info_req *req; 771 + struct be_dma_mem nonemb_cmd; 772 + int rc; 773 + 774 + if (mgmt_get_all_if_id(phba)) 775 + return -EIO; 776 + 777 + rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd, 778 + OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO, 779 + sizeof(*if_info)); 780 + if (rc) 781 + return rc; 782 + 783 + req = nonemb_cmd.va; 784 + req->interface_hndl = phba->interface_handle; 785 + req->ip_type = ip_type; 786 + 787 + return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, if_info, 788 + sizeof(*if_info)); 789 + } 790 + 791 + int mgmt_get_nic_conf(struct beiscsi_hba *phba, 792 + struct be_cmd_get_nic_conf_resp *nic) 793 + { 794 + struct be_dma_mem nonemb_cmd; 795 + int rc; 796 + 797 + rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd, 798 + OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG, 799 + sizeof(*nic)); 800 + if (rc) 801 + return rc; 802 + 803 + return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, nic, sizeof(*nic)); 804 + } 805 + 806 + 807 + 808 + unsigned int be_cmd_get_initname(struct beiscsi_hba *phba) 809 + { 810 + unsigned int tag = 0; 811 + struct be_mcc_wrb *wrb; 812 + struct be_cmd_hba_name *req; 813 + struct be_ctrl_info *ctrl = &phba->ctrl; 814 + 497 815 spin_lock(&ctrl->mbox_lock); 498 816 tag = alloc_mcc_tag(phba); 499 817 if (!tag) { ··· 890 438 req = embedded_payload(wrb); 891 439 wrb->tag0 |= tag; 892 440 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 893 - be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 894 - OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG, 895 - sizeof(*req)); 441 + be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, 442 + OPCODE_ISCSI_INI_CFG_GET_HBA_NAME, 443 + sizeof(*req)); 896 444 897 445 be_mcc_notify(phba); 898 446 spin_unlock(&ctrl->mbox_lock); 899 447 return tag; 900 448 } 901 449 450 + unsigned int be_cmd_get_port_speed(struct beiscsi_hba *phba) 451 + { 452 + unsigned int tag = 0; 453 + struct be_mcc_wrb *wrb; 454 + struct be_cmd_ntwk_link_status_req *req; 455 + struct be_ctrl_info *ctrl = &phba->ctrl; 456 + 457 + spin_lock(&ctrl->mbox_lock); 458 + tag = alloc_mcc_tag(phba); 459 + if (!tag) { 460 + spin_unlock(&ctrl->mbox_lock); 461 + return tag; 462 + } 463 + 464 + wrb = wrb_from_mccq(phba); 465 + req = embedded_payload(wrb); 466 + wrb->tag0 |= tag; 467 + be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 468 + be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, 469 + OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, 470 + sizeof(*req)); 471 + 472 + be_mcc_notify(phba); 473 + spin_unlock(&ctrl->mbox_lock); 474 + return tag; 475 + }
+46 -4
drivers/scsi/be2iscsi/be_mgmt.h
··· 20 20 #ifndef _BEISCSI_MGMT_ 21 21 #define _BEISCSI_MGMT_ 22 22 23 - #include <linux/types.h> 24 - #include <linux/list.h> 23 + #include <scsi/scsi_bsg_iscsi.h> 25 24 #include "be_iscsi.h" 26 25 #include "be_main.h" 26 + 27 + #define IP_ACTION_ADD 0x01 28 + #define IP_ACTION_DEL 0x02 29 + 30 + #define IP_V6_LEN 16 31 + #define IP_V4_LEN 4 27 32 28 33 /** 29 34 * Pseudo amap definition in which each bit of the actual structure is defined ··· 103 98 struct invalidate_command_table *inv_tbl, 104 99 unsigned int num_invalidate, unsigned int cid, 105 100 struct be_dma_mem *nonemb_cmd); 101 + unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl, 102 + struct beiscsi_hba *phba, 103 + struct bsg_job *job, 104 + struct be_dma_mem *nonemb_cmd); 106 105 107 106 struct iscsi_invalidate_connection_params_in { 108 107 struct be_cmd_req_hdr hdr; ··· 213 204 struct mgmt_controller_attributes params; 214 205 } __packed; 215 206 207 + struct be_bsg_vendor_cmd { 208 + struct be_cmd_req_hdr hdr; 209 + unsigned short region; 210 + unsigned short offset; 211 + unsigned short sector; 212 + } __packed; 213 + 216 214 /* configuration management */ 217 215 218 216 #define GET_MGMT_CONTROLLER_WS(phba) (phba->pmgmt_ws) ··· 235 219 /* the CMD_RESPONSE_HEADER */ 236 220 237 221 #define ISCSI_GET_PDU_TEMPLATE_ADDRESS(pc, pa) {\ 238 - pa->lo = phba->init_mem[ISCSI_MEM_GLOBAL_HEADER].mem_array[0].\ 222 + pa->lo = phba->init_mem[ISCSI_MEM_GLOBAL_HEADER].mem_array[0].\ 239 223 bus_address.u.a32.address_lo; \ 240 - pa->hi = phba->init_mem[ISCSI_MEM_GLOBAL_HEADER].mem_array[0].\ 224 + pa->hi = phba->init_mem[ISCSI_MEM_GLOBAL_HEADER].mem_array[0].\ 241 225 bus_address.u.a32.address_hi; \ 242 226 } 227 + 228 + #define BEISCSI_WRITE_FLASH 0 229 + #define BEISCSI_READ_FLASH 1 243 230 244 231 struct beiscsi_endpoint { 245 232 struct beiscsi_hba *phba; ··· 266 247 unsigned short cid, 267 248 unsigned short issue_reset, 268 249 unsigned short savecfg_flag); 250 + 251 + int mgmt_set_ip(struct beiscsi_hba *phba, 252 + struct iscsi_iface_param_info *ip_param, 253 + struct iscsi_iface_param_info *subnet_param, 254 + uint32_t boot_proto); 255 + 256 + unsigned int mgmt_get_boot_target(struct beiscsi_hba *phba); 257 + 258 + unsigned int mgmt_get_session_info(struct beiscsi_hba *phba, 259 + u32 boot_session_handle, 260 + struct be_dma_mem *nonemb_cmd); 261 + 262 + int mgmt_get_nic_conf(struct beiscsi_hba *phba, 263 + struct be_cmd_get_nic_conf_resp *mac); 264 + 265 + int mgmt_get_if_info(struct beiscsi_hba *phba, int ip_type, 266 + struct be_cmd_get_if_info_resp *if_info); 267 + 268 + int mgmt_get_gateway(struct beiscsi_hba *phba, int ip_type, 269 + struct be_cmd_get_def_gateway_resp *gateway); 270 + 271 + int mgmt_set_gateway(struct beiscsi_hba *phba, 272 + struct iscsi_iface_param_info *gateway_param); 269 273 270 274 #endif
-3
drivers/scsi/bfa/bfa_fcs.h
··· 799 799 enum bfa_lport_role roles, 800 800 struct bfad_vf_s *vf_drv, 801 801 struct bfad_vport_s *vp_drv); 802 - void bfa_fcb_lport_delete(struct bfad_s *bfad, enum bfa_lport_role roles, 803 - struct bfad_vf_s *vf_drv, 804 - struct bfad_vport_s *vp_drv); 805 802 806 803 /* 807 804 * vport callbacks
+19 -17
drivers/scsi/bfa/bfa_fcs_lport.c
··· 616 616 __port_action[port->fabric->fab_type].online(port); 617 617 618 618 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port)); 619 - BFA_LOG(KERN_INFO, bfad, bfa_log_level, 619 + BFA_LOG(KERN_WARNING, bfad, bfa_log_level, 620 620 "Logical port online: WWN = %s Role = %s\n", 621 621 lpwwn_buf, "Initiator"); 622 622 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_ONLINE); ··· 639 639 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port)); 640 640 if (bfa_sm_cmp_state(port->fabric, 641 641 bfa_fcs_fabric_sm_online) == BFA_TRUE) { 642 - BFA_LOG(KERN_ERR, bfad, bfa_log_level, 642 + BFA_LOG(KERN_WARNING, bfad, bfa_log_level, 643 643 "Logical port lost fabric connectivity: WWN = %s Role = %s\n", 644 644 lpwwn_buf, "Initiator"); 645 645 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DISCONNECT); 646 646 } else { 647 - BFA_LOG(KERN_INFO, bfad, bfa_log_level, 647 + BFA_LOG(KERN_WARNING, bfad, bfa_log_level, 648 648 "Logical port taken offline: WWN = %s Role = %s\n", 649 649 lpwwn_buf, "Initiator"); 650 650 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_OFFLINE); ··· 709 709 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DELETE); 710 710 711 711 /* Base port will be deleted by the OS driver */ 712 - if (port->vport) { 713 - bfa_fcb_lport_delete(port->fcs->bfad, port->port_cfg.roles, 714 - port->fabric->vf_drv, 715 - port->vport ? port->vport->vport_drv : NULL); 712 + if (port->vport) 716 713 bfa_fcs_vport_delete_comp(port->vport); 717 - } else { 714 + else 718 715 bfa_wc_down(&port->fabric->wc); 719 - } 720 716 } 721 717 722 718 ··· 5710 5714 (struct bfad_vport_s *)vport->vport_drv; 5711 5715 5712 5716 bfa_fcs_fabric_delvport(__vport_fabric(vport), vport); 5713 - 5714 - if (vport_drv->comp_del) 5715 - complete(vport_drv->comp_del); 5716 - else 5717 - kfree(vport_drv); 5718 - 5719 5717 bfa_lps_delete(vport->lps); 5718 + 5719 + if (vport_drv->comp_del) { 5720 + complete(vport_drv->comp_del); 5721 + return; 5722 + } 5723 + 5724 + /* 5725 + * We queue the vport delete work to the IM work_q from here. 5726 + * The memory for the bfad_vport_s is freed from the FC function 5727 + * template vport_delete entry point. 5728 + */ 5729 + if (vport_drv) 5730 + bfad_im_port_delete(vport_drv->drv_port.bfad, 5731 + &vport_drv->drv_port); 5720 5732 } 5721 - 5722 - 5723 5733 5724 5734 /* 5725 5735 * fcs_vport_public FCS virtual port public interfaces
-17
drivers/scsi/bfa/bfad.c
··· 456 456 return port_drv; 457 457 } 458 458 459 - void 460 - bfa_fcb_lport_delete(struct bfad_s *bfad, enum bfa_lport_role roles, 461 - struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv) 462 - { 463 - struct bfad_port_s *port_drv; 464 - 465 - /* this will be only called from rmmod context */ 466 - if (vp_drv && !vp_drv->comp_del) { 467 - port_drv = (vp_drv) ? (&(vp_drv)->drv_port) : 468 - ((vf_drv) ? (&(vf_drv)->base_port) : 469 - (&(bfad)->pport)); 470 - bfa_trc(bfad, roles); 471 - if (roles & BFA_LPORT_ROLE_FCP_IM) 472 - bfad_im_port_delete(bfad, port_drv); 473 - } 474 - } 475 - 476 459 /* 477 460 * FCS RPORT alloc callback, after successful PLOGI by FCS 478 461 */
+3 -17
drivers/scsi/bfa/bfad_attr.c
··· 497 497 if (im_port->flags & BFAD_PORT_DELETE) { 498 498 bfad_scsi_host_free(bfad, im_port); 499 499 list_del(&vport->list_entry); 500 + kfree(vport); 500 501 return 0; 501 502 } 502 503 ··· 759 758 else if (!strcmp(model, "Brocade-804")) 760 759 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 761 760 "Brocade 8Gbps FC HBA for HP Bladesystem C-class"); 762 - else if (!strcmp(model, "Brocade-902") || 763 - !strcmp(model, "Brocade-1741")) 761 + else if (!strcmp(model, "Brocade-1741")) 764 762 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 765 763 "Brocade 10Gbps CNA for Dell M-Series Blade Servers"); 766 - else if (strstr(model, "Brocade-1560")) { 767 - if (nports == 1) 768 - snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 769 - "Brocade 16Gbps PCIe single port FC HBA"); 770 - else 771 - snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 772 - "Brocade 16Gbps PCIe dual port FC HBA"); 773 - } else if (strstr(model, "Brocade-1710")) { 774 - if (nports == 1) 775 - snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 776 - "Brocade 10Gbps single port CNA"); 777 - else 778 - snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 779 - "Brocade 10Gbps dual port CNA"); 780 - } else if (strstr(model, "Brocade-1860")) { 764 + else if (strstr(model, "Brocade-1860")) { 781 765 if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc)) 782 766 snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 783 767 "Brocade 10Gbps single port CNA");
+1 -1
drivers/scsi/bnx2i/57xx_iscsi_constants.h
··· 1 1 /* 57xx_iscsi_constants.h: Broadcom NetXtreme II iSCSI HSI 2 2 * 3 - * Copyright (c) 2006 - 2011 Broadcom Corporation 3 + * Copyright (c) 2006 - 2012 Broadcom Corporation 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify 6 6 * it under the terms of the GNU General Public License as published by
+1 -1
drivers/scsi/bnx2i/57xx_iscsi_hsi.h
··· 1 1 /* 57xx_iscsi_hsi.h: Broadcom NetXtreme II iSCSI HSI. 2 2 * 3 - * Copyright (c) 2006 - 2011 Broadcom Corporation 3 + * Copyright (c) 2006 - 2012 Broadcom Corporation 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify 6 6 * it under the terms of the GNU General Public License as published by
+1 -1
drivers/scsi/bnx2i/bnx2i.h
··· 1 1 /* bnx2i.h: Broadcom NetXtreme II iSCSI driver. 2 2 * 3 - * Copyright (c) 2006 - 2011 Broadcom Corporation 3 + * Copyright (c) 2006 - 2012 Broadcom Corporation 4 4 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved. 5 5 * Copyright (c) 2007, 2008 Mike Christie 6 6 *
+1 -1
drivers/scsi/bnx2i/bnx2i_hwi.c
··· 1 1 /* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver. 2 2 * 3 - * Copyright (c) 2006 - 2011 Broadcom Corporation 3 + * Copyright (c) 2006 - 2012 Broadcom Corporation 4 4 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved. 5 5 * Copyright (c) 2007, 2008 Mike Christie 6 6 *
+3 -3
drivers/scsi/bnx2i/bnx2i_init.c
··· 1 1 /* bnx2i.c: Broadcom NetXtreme II iSCSI driver. 2 2 * 3 - * Copyright (c) 2006 - 2011 Broadcom Corporation 3 + * Copyright (c) 2006 - 2012 Broadcom Corporation 4 4 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved. 5 5 * Copyright (c) 2007, 2008 Mike Christie 6 6 * ··· 18 18 static u32 adapter_count; 19 19 20 20 #define DRV_MODULE_NAME "bnx2i" 21 - #define DRV_MODULE_VERSION "2.7.0.3" 22 - #define DRV_MODULE_RELDATE "Jun 15, 2011" 21 + #define DRV_MODULE_VERSION "2.7.2.2" 22 + #define DRV_MODULE_RELDATE "Apr 25, 2012" 23 23 24 24 static char version[] __devinitdata = 25 25 "Broadcom NetXtreme II iSCSI Driver " DRV_MODULE_NAME \
+2 -1
drivers/scsi/bnx2i/bnx2i_iscsi.c
··· 1 1 /* 2 2 * bnx2i_iscsi.c: Broadcom NetXtreme II iSCSI driver. 3 3 * 4 - * Copyright (c) 2006 - 2011 Broadcom Corporation 4 + * Copyright (c) 2006 - 2012 Broadcom Corporation 5 5 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved. 6 6 * Copyright (c) 2007, 2008 Mike Christie 7 7 * ··· 2244 2244 .eh_device_reset_handler = iscsi_eh_device_reset, 2245 2245 .eh_target_reset_handler = iscsi_eh_recover_target, 2246 2246 .change_queue_depth = iscsi_change_queue_depth, 2247 + .target_alloc = iscsi_target_alloc, 2247 2248 .can_queue = 2048, 2248 2249 .max_sectors = 127, 2249 2250 .cmd_per_lun = 128,
+1 -1
drivers/scsi/bnx2i/bnx2i_sysfs.c
··· 1 1 /* bnx2i_sysfs.c: Broadcom NetXtreme II iSCSI driver. 2 2 * 3 - * Copyright (c) 2004 - 2011 Broadcom Corporation 3 + * Copyright (c) 2004 - 2012 Broadcom Corporation 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify 6 6 * it under the terms of the GNU General Public License as published by
+66 -4
drivers/scsi/device_handler/scsi_dh_alua.c
··· 55 55 #define ALUA_FAILOVER_TIMEOUT (60 * HZ) 56 56 #define ALUA_FAILOVER_RETRIES 5 57 57 58 + /* flags passed from user level */ 59 + #define ALUA_OPTIMIZE_STPG 1 60 + 58 61 struct alua_dh_data { 59 62 int group_id; 60 63 int rel_port; 61 64 int tpgs; 62 65 int state; 66 + int pref; 67 + unsigned flags; /* used for optimizing STPG */ 63 68 unsigned char inq[ALUA_INQUIRY_SIZE]; 64 69 unsigned char *buff; 65 70 int bufflen; ··· 559 554 for (k = 4, ucp = h->buff + 4; k < len; k += off, ucp += off) { 560 555 if (h->group_id == (ucp[2] << 8) + ucp[3]) { 561 556 h->state = ucp[0] & 0x0f; 557 + h->pref = ucp[0] >> 7; 562 558 valid_states = ucp[1]; 563 559 } 564 560 off = 8 + (ucp[7] * 4); 565 561 } 566 562 567 563 sdev_printk(KERN_INFO, sdev, 568 - "%s: port group %02x state %c supports %c%c%c%c%c%c%c\n", 564 + "%s: port group %02x state %c %s supports %c%c%c%c%c%c%c\n", 569 565 ALUA_DH_NAME, h->group_id, print_alua_state(h->state), 566 + h->pref ? "preferred" : "non-preferred", 570 567 valid_states&TPGS_SUPPORT_TRANSITION?'T':'t', 571 568 valid_states&TPGS_SUPPORT_OFFLINE?'O':'o', 572 569 valid_states&TPGS_SUPPORT_LBA_DEPENDENT?'L':'l', ··· 628 621 out: 629 622 return err; 630 623 } 624 + /* 625 + * alua_set_params - set/unset the optimize flag 626 + * @sdev: device on the path to be activated 627 + * params - parameters in the following format 628 + * "no_of_params\0param1\0param2\0param3\0...\0" 629 + * For example, to set the flag pass the following parameters 630 + * from multipath.conf 631 + * hardware_handler "2 alua 1" 632 + */ 633 + static int alua_set_params(struct scsi_device *sdev, const char *params) 634 + { 635 + struct alua_dh_data *h = get_alua_data(sdev); 636 + unsigned int optimize = 0, argc; 637 + const char *p = params; 638 + int result = SCSI_DH_OK; 639 + 640 + if ((sscanf(params, "%u", &argc) != 1) || (argc != 1)) 641 + return -EINVAL; 642 + 643 + while (*p++) 644 + ; 645 + if ((sscanf(p, "%u", &optimize) != 1) || (optimize > 1)) 646 + return -EINVAL; 647 + 648 + if (optimize) 649 + h->flags |= ALUA_OPTIMIZE_STPG; 650 + else 651 + h->flags &= ~ALUA_OPTIMIZE_STPG; 652 + 653 + return result; 654 + } 631 655 632 656 /* 633 657 * alua_activate - activate a path ··· 675 637 { 676 638 struct alua_dh_data *h = get_alua_data(sdev); 677 639 int err = SCSI_DH_OK; 640 + int stpg = 0; 678 641 679 642 err = alua_rtpg(sdev, h); 680 643 if (err != SCSI_DH_OK) 681 644 goto out; 682 645 683 - if (h->tpgs & TPGS_MODE_EXPLICIT && 684 - h->state != TPGS_STATE_OPTIMIZED && 685 - h->state != TPGS_STATE_LBA_DEPENDENT) { 646 + if (h->tpgs & TPGS_MODE_EXPLICIT) { 647 + switch (h->state) { 648 + case TPGS_STATE_NONOPTIMIZED: 649 + stpg = 1; 650 + if ((h->flags & ALUA_OPTIMIZE_STPG) && 651 + (!h->pref) && 652 + (h->tpgs & TPGS_MODE_IMPLICIT)) 653 + stpg = 0; 654 + break; 655 + case TPGS_STATE_STANDBY: 656 + stpg = 1; 657 + break; 658 + case TPGS_STATE_UNAVAILABLE: 659 + case TPGS_STATE_OFFLINE: 660 + err = SCSI_DH_IO; 661 + break; 662 + case TPGS_STATE_TRANSITIONING: 663 + err = SCSI_DH_RETRY; 664 + break; 665 + default: 666 + break; 667 + } 668 + } 669 + 670 + if (stpg) { 686 671 h->callback_fn = fn; 687 672 h->callback_data = data; 688 673 err = submit_stpg(h); ··· 759 698 .prep_fn = alua_prep_fn, 760 699 .check_sense = alua_check_sense, 761 700 .activate = alua_activate, 701 + .set_params = alua_set_params, 762 702 .match = alua_match, 763 703 }; 764 704
+30 -11
drivers/scsi/fcoe/fcoe.c
··· 411 411 } 412 412 413 413 /** 414 - * fcoe_interface_cleanup() - Clean up a FCoE interface 414 + * fcoe_interface_remove() - remove FCoE interface from netdev 415 415 * @fcoe: The FCoE interface to be cleaned up 416 416 * 417 417 * Caller must be holding the RTNL mutex 418 418 */ 419 - static void fcoe_interface_cleanup(struct fcoe_interface *fcoe) 419 + static void fcoe_interface_remove(struct fcoe_interface *fcoe) 420 420 { 421 421 struct net_device *netdev = fcoe->netdev; 422 422 struct fcoe_ctlr *fip = &fcoe->ctlr; 423 423 u8 flogi_maddr[ETH_ALEN]; 424 424 const struct net_device_ops *ops; 425 - 426 - rtnl_lock(); 427 425 428 426 /* 429 427 * Don't listen for Ethernet packets anymore. ··· 451 453 FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE" 452 454 " specific feature for LLD.\n"); 453 455 } 456 + fcoe->removed = 1; 457 + } 454 458 459 + 460 + /** 461 + * fcoe_interface_cleanup() - Clean up a FCoE interface 462 + * @fcoe: The FCoE interface to be cleaned up 463 + */ 464 + static void fcoe_interface_cleanup(struct fcoe_interface *fcoe) 465 + { 466 + struct net_device *netdev = fcoe->netdev; 467 + struct fcoe_ctlr *fip = &fcoe->ctlr; 468 + 469 + rtnl_lock(); 470 + if (!fcoe->removed) 471 + fcoe_interface_remove(fcoe); 455 472 rtnl_unlock(); 456 473 457 474 /* Release the self-reference taken during fcoe_interface_create() */ 458 475 /* tear-down the FCoE controller */ 459 476 fcoe_ctlr_destroy(fip); 477 + scsi_host_put(fcoe->ctlr.lp->host); 460 478 kfree(fcoe); 461 479 dev_put(netdev); 462 480 module_put(THIS_MODULE); ··· 536 522 struct fcoe_port *port = lport_priv(lport); 537 523 struct fcoe_interface *fcoe = port->priv; 538 524 539 - rtnl_lock(); 540 525 if (!is_zero_ether_addr(port->data_src_addr)) 541 526 dev_uc_del(fcoe->netdev, port->data_src_addr); 542 527 if (!is_zero_ether_addr(addr)) 543 528 dev_uc_add(fcoe->netdev, addr); 544 529 memcpy(port->data_src_addr, addr, ETH_ALEN); 545 - rtnl_unlock(); 546 530 } 547 531 548 532 /** ··· 953 941 rtnl_lock(); 954 942 if (!is_zero_ether_addr(port->data_src_addr)) 955 943 dev_uc_del(netdev, port->data_src_addr); 944 + if (lport->vport) 945 + synchronize_net(); 946 + else 947 + fcoe_interface_remove(fcoe); 956 948 rtnl_unlock(); 957 949 958 950 /* Free queued packets for the per-CPU receive threads */ ··· 975 959 /* Free memory used by statistical counters */ 976 960 fc_lport_free_stats(lport); 977 961 978 - /* Release the Scsi_Host */ 979 - scsi_host_put(lport->host); 962 + /* 963 + * Release the Scsi_Host for vport but hold on to 964 + * master lport until it fcoe interface fully cleaned-up. 965 + */ 966 + if (lport->vport) 967 + scsi_host_put(lport->host); 980 968 } 981 969 982 970 /** ··· 2294 2274 continue; 2295 2275 2296 2276 skb = dev_alloc_skb(0); 2297 - if (!skb) { 2298 - spin_unlock_bh(&pp->fcoe_rx_list.lock); 2277 + if (!skb) 2299 2278 continue; 2300 - } 2279 + 2301 2280 skb->destructor = fcoe_percpu_flush_done; 2302 2281 2303 2282 spin_lock_bh(&pp->fcoe_rx_list.lock);
+3 -1
drivers/scsi/fcoe/fcoe.h
··· 71 71 * @ctlr: The FCoE controller (for FIP) 72 72 * @oem: The offload exchange manager for all local port 73 73 * instances associated with this port 74 - * This structure is 1:1 with a net devive. 74 + * @removed: Indicates fcoe interface removed from net device 75 + * This structure is 1:1 with a net device. 75 76 */ 76 77 struct fcoe_interface { 77 78 struct list_head list; ··· 82 81 struct packet_type fip_packet_type; 83 82 struct fcoe_ctlr ctlr; 84 83 struct fc_exch_mgr *oem; 84 + u8 removed; 85 85 }; 86 86 87 87 #define fcoe_from_ctlr(fip) container_of(fip, struct fcoe_interface, ctlr)
+7 -1
drivers/scsi/fcoe/fcoe_ctlr.c
··· 1883 1883 frame = (struct fip_frame *)skb->data; 1884 1884 memset(frame, 0, len); 1885 1885 memcpy(frame->eth.h_dest, dest, ETH_ALEN); 1886 - memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); 1886 + 1887 + if (sub == FIP_SC_VN_BEACON) { 1888 + hton24(frame->eth.h_source, FIP_VN_FC_MAP); 1889 + hton24(frame->eth.h_source + 3, fip->port_id); 1890 + } else { 1891 + memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); 1892 + } 1887 1893 frame->eth.h_proto = htons(ETH_P_FIP); 1888 1894 1889 1895 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
+546 -139
drivers/scsi/hpsa.c
··· 159 159 int qdepth, int reason); 160 160 161 161 static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd); 162 + static int hpsa_eh_abort_handler(struct scsi_cmnd *scsicmd); 162 163 static int hpsa_slave_alloc(struct scsi_device *sdev); 163 164 static void hpsa_slave_destroy(struct scsi_device *sdev); 164 165 ··· 172 171 static void calc_bucket_map(int *bucket, int num_buckets, 173 172 int nsgs, int *bucket_map); 174 173 static __devinit void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h); 175 - static inline u32 next_command(struct ctlr_info *h); 174 + static inline u32 next_command(struct ctlr_info *h, u8 q); 176 175 static int __devinit hpsa_find_cfg_addrs(struct pci_dev *pdev, 177 176 void __iomem *vaddr, u32 *cfg_base_addr, u64 *cfg_base_addr_index, 178 177 u64 *cfg_offset); ··· 181 180 static int __devinit hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id); 182 181 static int __devinit hpsa_wait_for_board_state(struct pci_dev *pdev, 183 182 void __iomem *vaddr, int wait_for_ready); 183 + static inline void finish_cmd(struct CommandList *c); 184 184 #define BOARD_NOT_READY 0 185 185 #define BOARD_READY 1 186 186 ··· 233 231 "unit attention detected\n", h->ctlr); 234 232 break; 235 233 } 234 + return 1; 235 + } 236 + 237 + static int check_for_busy(struct ctlr_info *h, struct CommandList *c) 238 + { 239 + if (c->err_info->CommandStatus != CMD_TARGET_STATUS || 240 + (c->err_info->ScsiStatus != SAM_STAT_BUSY && 241 + c->err_info->ScsiStatus != SAM_STAT_TASK_SET_FULL)) 242 + return 0; 243 + dev_warn(&h->pdev->dev, HPSA "device busy"); 236 244 return 1; 237 245 } 238 246 ··· 380 368 } 381 369 382 370 static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG", 383 - "UNKNOWN" 371 + "1(ADM)", "UNKNOWN" 384 372 }; 385 373 #define RAID_UNKNOWN (ARRAY_SIZE(raid_label) - 1) 386 374 ··· 509 497 .change_queue_depth = hpsa_change_queue_depth, 510 498 .this_id = -1, 511 499 .use_clustering = ENABLE_CLUSTERING, 500 + .eh_abort_handler = hpsa_eh_abort_handler, 512 501 .eh_device_reset_handler = hpsa_eh_device_reset_handler, 513 502 .ioctl = hpsa_ioctl, 514 503 .slave_alloc = hpsa_slave_alloc, ··· 529 516 list_add_tail(&c->list, list); 530 517 } 531 518 532 - static inline u32 next_command(struct ctlr_info *h) 519 + static inline u32 next_command(struct ctlr_info *h, u8 q) 533 520 { 534 521 u32 a; 522 + struct reply_pool *rq = &h->reply_queue[q]; 523 + unsigned long flags; 535 524 536 525 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant))) 537 - return h->access.command_completed(h); 526 + return h->access.command_completed(h, q); 538 527 539 - if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) { 540 - a = *(h->reply_pool_head); /* Next cmd in ring buffer */ 541 - (h->reply_pool_head)++; 528 + if ((rq->head[rq->current_entry] & 1) == rq->wraparound) { 529 + a = rq->head[rq->current_entry]; 530 + rq->current_entry++; 531 + spin_lock_irqsave(&h->lock, flags); 542 532 h->commands_outstanding--; 533 + spin_unlock_irqrestore(&h->lock, flags); 543 534 } else { 544 535 a = FIFO_EMPTY; 545 536 } 546 537 /* Check for wraparound */ 547 - if (h->reply_pool_head == (h->reply_pool + h->max_commands)) { 548 - h->reply_pool_head = h->reply_pool; 549 - h->reply_pool_wraparound ^= 1; 538 + if (rq->current_entry == h->max_commands) { 539 + rq->current_entry = 0; 540 + rq->wraparound ^= 1; 550 541 } 551 542 return a; 552 543 } ··· 561 544 */ 562 545 static void set_performant_mode(struct ctlr_info *h, struct CommandList *c) 563 546 { 564 - if (likely(h->transMethod & CFGTBL_Trans_Performant)) 547 + if (likely(h->transMethod & CFGTBL_Trans_Performant)) { 565 548 c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1); 549 + if (likely(h->msix_vector)) 550 + c->Header.ReplyQueue = 551 + smp_processor_id() % h->nreply_queues; 552 + } 553 + } 554 + 555 + static int is_firmware_flash_cmd(u8 *cdb) 556 + { 557 + return cdb[0] == BMIC_WRITE && cdb[6] == BMIC_FLASH_FIRMWARE; 558 + } 559 + 560 + /* 561 + * During firmware flash, the heartbeat register may not update as frequently 562 + * as it should. So we dial down lockup detection during firmware flash. and 563 + * dial it back up when firmware flash completes. 564 + */ 565 + #define HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH (240 * HZ) 566 + #define HEARTBEAT_SAMPLE_INTERVAL (30 * HZ) 567 + static void dial_down_lockup_detection_during_fw_flash(struct ctlr_info *h, 568 + struct CommandList *c) 569 + { 570 + if (!is_firmware_flash_cmd(c->Request.CDB)) 571 + return; 572 + atomic_inc(&h->firmware_flash_in_progress); 573 + h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL_DURING_FLASH; 574 + } 575 + 576 + static void dial_up_lockup_detection_on_fw_flash_complete(struct ctlr_info *h, 577 + struct CommandList *c) 578 + { 579 + if (is_firmware_flash_cmd(c->Request.CDB) && 580 + atomic_dec_and_test(&h->firmware_flash_in_progress)) 581 + h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; 566 582 } 567 583 568 584 static void enqueue_cmd_and_start_io(struct ctlr_info *h, ··· 604 554 unsigned long flags; 605 555 606 556 set_performant_mode(h, c); 557 + dial_down_lockup_detection_during_fw_flash(h, c); 607 558 spin_lock_irqsave(&h->lock, flags); 608 559 addQ(&h->reqQ, c); 609 560 h->Qdepth++; 610 - start_io(h); 611 561 spin_unlock_irqrestore(&h->lock, flags); 562 + start_io(h); 612 563 } 613 564 614 565 static inline void removeQ(struct CommandList *c) ··· 1244 1193 break; 1245 1194 } 1246 1195 /* Must be some other type of check condition */ 1247 - dev_warn(&h->pdev->dev, "cp %p has check condition: " 1196 + dev_dbg(&h->pdev->dev, "cp %p has check condition: " 1248 1197 "unknown type: " 1249 1198 "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, " 1250 1199 "Returning result: 0x%x, " ··· 1421 1370 } 1422 1371 } 1423 1372 1373 + #define MAX_DRIVER_CMD_RETRIES 25 1424 1374 static void hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h, 1425 1375 struct CommandList *c, int data_direction) 1426 1376 { 1427 - int retry_count = 0; 1377 + int backoff_time = 10, retry_count = 0; 1428 1378 1429 1379 do { 1430 1380 memset(c->err_info, 0, sizeof(*c->err_info)); 1431 1381 hpsa_scsi_do_simple_cmd_core(h, c); 1432 1382 retry_count++; 1433 - } while (check_for_unit_attention(h, c) && retry_count <= 3); 1383 + if (retry_count > 3) { 1384 + msleep(backoff_time); 1385 + if (backoff_time < 1000) 1386 + backoff_time *= 2; 1387 + } 1388 + } while ((check_for_unit_attention(h, c) || 1389 + check_for_busy(h, c)) && 1390 + retry_count <= MAX_DRIVER_CMD_RETRIES); 1434 1391 hpsa_pci_unmap(h->pdev, c, 1, data_direction); 1435 1392 } 1436 1393 ··· 2124 2065 done(cmd); 2125 2066 return 0; 2126 2067 } 2127 - /* Need a lock as this is being allocated from the pool */ 2128 - c = cmd_alloc(h); 2129 2068 spin_unlock_irqrestore(&h->lock, flags); 2069 + c = cmd_alloc(h); 2130 2070 if (c == NULL) { /* trouble... */ 2131 2071 dev_err(&h->pdev->dev, "cmd_alloc returned NULL!\n"); 2132 2072 return SCSI_MLQUEUE_HOST_BUSY; ··· 2392 2334 return FAILED; 2393 2335 } 2394 2336 2337 + static void swizzle_abort_tag(u8 *tag) 2338 + { 2339 + u8 original_tag[8]; 2340 + 2341 + memcpy(original_tag, tag, 8); 2342 + tag[0] = original_tag[3]; 2343 + tag[1] = original_tag[2]; 2344 + tag[2] = original_tag[1]; 2345 + tag[3] = original_tag[0]; 2346 + tag[4] = original_tag[7]; 2347 + tag[5] = original_tag[6]; 2348 + tag[6] = original_tag[5]; 2349 + tag[7] = original_tag[4]; 2350 + } 2351 + 2352 + static int hpsa_send_abort(struct ctlr_info *h, unsigned char *scsi3addr, 2353 + struct CommandList *abort, int swizzle) 2354 + { 2355 + int rc = IO_OK; 2356 + struct CommandList *c; 2357 + struct ErrorInfo *ei; 2358 + 2359 + c = cmd_special_alloc(h); 2360 + if (c == NULL) { /* trouble... */ 2361 + dev_warn(&h->pdev->dev, "cmd_special_alloc returned NULL!\n"); 2362 + return -ENOMEM; 2363 + } 2364 + 2365 + fill_cmd(c, HPSA_ABORT_MSG, h, abort, 0, 0, scsi3addr, TYPE_MSG); 2366 + if (swizzle) 2367 + swizzle_abort_tag(&c->Request.CDB[4]); 2368 + hpsa_scsi_do_simple_cmd_core(h, c); 2369 + dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: do_simple_cmd_core completed.\n", 2370 + __func__, abort->Header.Tag.upper, abort->Header.Tag.lower); 2371 + /* no unmap needed here because no data xfer. */ 2372 + 2373 + ei = c->err_info; 2374 + switch (ei->CommandStatus) { 2375 + case CMD_SUCCESS: 2376 + break; 2377 + case CMD_UNABORTABLE: /* Very common, don't make noise. */ 2378 + rc = -1; 2379 + break; 2380 + default: 2381 + dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: interpreting error.\n", 2382 + __func__, abort->Header.Tag.upper, 2383 + abort->Header.Tag.lower); 2384 + hpsa_scsi_interpret_error(c); 2385 + rc = -1; 2386 + break; 2387 + } 2388 + cmd_special_free(h, c); 2389 + dev_dbg(&h->pdev->dev, "%s: Tag:0x%08x:%08x: Finished.\n", __func__, 2390 + abort->Header.Tag.upper, abort->Header.Tag.lower); 2391 + return rc; 2392 + } 2393 + 2394 + /* 2395 + * hpsa_find_cmd_in_queue 2396 + * 2397 + * Used to determine whether a command (find) is still present 2398 + * in queue_head. Optionally excludes the last element of queue_head. 2399 + * 2400 + * This is used to avoid unnecessary aborts. Commands in h->reqQ have 2401 + * not yet been submitted, and so can be aborted by the driver without 2402 + * sending an abort to the hardware. 2403 + * 2404 + * Returns pointer to command if found in queue, NULL otherwise. 2405 + */ 2406 + static struct CommandList *hpsa_find_cmd_in_queue(struct ctlr_info *h, 2407 + struct scsi_cmnd *find, struct list_head *queue_head) 2408 + { 2409 + unsigned long flags; 2410 + struct CommandList *c = NULL; /* ptr into cmpQ */ 2411 + 2412 + if (!find) 2413 + return 0; 2414 + spin_lock_irqsave(&h->lock, flags); 2415 + list_for_each_entry(c, queue_head, list) { 2416 + if (c->scsi_cmd == NULL) /* e.g.: passthru ioctl */ 2417 + continue; 2418 + if (c->scsi_cmd == find) { 2419 + spin_unlock_irqrestore(&h->lock, flags); 2420 + return c; 2421 + } 2422 + } 2423 + spin_unlock_irqrestore(&h->lock, flags); 2424 + return NULL; 2425 + } 2426 + 2427 + static struct CommandList *hpsa_find_cmd_in_queue_by_tag(struct ctlr_info *h, 2428 + u8 *tag, struct list_head *queue_head) 2429 + { 2430 + unsigned long flags; 2431 + struct CommandList *c; 2432 + 2433 + spin_lock_irqsave(&h->lock, flags); 2434 + list_for_each_entry(c, queue_head, list) { 2435 + if (memcmp(&c->Header.Tag, tag, 8) != 0) 2436 + continue; 2437 + spin_unlock_irqrestore(&h->lock, flags); 2438 + return c; 2439 + } 2440 + spin_unlock_irqrestore(&h->lock, flags); 2441 + return NULL; 2442 + } 2443 + 2444 + /* Some Smart Arrays need the abort tag swizzled, and some don't. It's hard to 2445 + * tell which kind we're dealing with, so we send the abort both ways. There 2446 + * shouldn't be any collisions between swizzled and unswizzled tags due to the 2447 + * way we construct our tags but we check anyway in case the assumptions which 2448 + * make this true someday become false. 2449 + */ 2450 + static int hpsa_send_abort_both_ways(struct ctlr_info *h, 2451 + unsigned char *scsi3addr, struct CommandList *abort) 2452 + { 2453 + u8 swizzled_tag[8]; 2454 + struct CommandList *c; 2455 + int rc = 0, rc2 = 0; 2456 + 2457 + /* we do not expect to find the swizzled tag in our queue, but 2458 + * check anyway just to be sure the assumptions which make this 2459 + * the case haven't become wrong. 2460 + */ 2461 + memcpy(swizzled_tag, &abort->Request.CDB[4], 8); 2462 + swizzle_abort_tag(swizzled_tag); 2463 + c = hpsa_find_cmd_in_queue_by_tag(h, swizzled_tag, &h->cmpQ); 2464 + if (c != NULL) { 2465 + dev_warn(&h->pdev->dev, "Unexpectedly found byte-swapped tag in completion queue.\n"); 2466 + return hpsa_send_abort(h, scsi3addr, abort, 0); 2467 + } 2468 + rc = hpsa_send_abort(h, scsi3addr, abort, 0); 2469 + 2470 + /* if the command is still in our queue, we can't conclude that it was 2471 + * aborted (it might have just completed normally) but in any case 2472 + * we don't need to try to abort it another way. 2473 + */ 2474 + c = hpsa_find_cmd_in_queue(h, abort->scsi_cmd, &h->cmpQ); 2475 + if (c) 2476 + rc2 = hpsa_send_abort(h, scsi3addr, abort, 1); 2477 + return rc && rc2; 2478 + } 2479 + 2480 + /* Send an abort for the specified command. 2481 + * If the device and controller support it, 2482 + * send a task abort request. 2483 + */ 2484 + static int hpsa_eh_abort_handler(struct scsi_cmnd *sc) 2485 + { 2486 + 2487 + int i, rc; 2488 + struct ctlr_info *h; 2489 + struct hpsa_scsi_dev_t *dev; 2490 + struct CommandList *abort; /* pointer to command to be aborted */ 2491 + struct CommandList *found; 2492 + struct scsi_cmnd *as; /* ptr to scsi cmd inside aborted command. */ 2493 + char msg[256]; /* For debug messaging. */ 2494 + int ml = 0; 2495 + 2496 + /* Find the controller of the command to be aborted */ 2497 + h = sdev_to_hba(sc->device); 2498 + if (WARN(h == NULL, 2499 + "ABORT REQUEST FAILED, Controller lookup failed.\n")) 2500 + return FAILED; 2501 + 2502 + /* Check that controller supports some kind of task abort */ 2503 + if (!(HPSATMF_PHYS_TASK_ABORT & h->TMFSupportFlags) && 2504 + !(HPSATMF_LOG_TASK_ABORT & h->TMFSupportFlags)) 2505 + return FAILED; 2506 + 2507 + memset(msg, 0, sizeof(msg)); 2508 + ml += sprintf(msg+ml, "ABORT REQUEST on C%d:B%d:T%d:L%d ", 2509 + h->scsi_host->host_no, sc->device->channel, 2510 + sc->device->id, sc->device->lun); 2511 + 2512 + /* Find the device of the command to be aborted */ 2513 + dev = sc->device->hostdata; 2514 + if (!dev) { 2515 + dev_err(&h->pdev->dev, "%s FAILED, Device lookup failed.\n", 2516 + msg); 2517 + return FAILED; 2518 + } 2519 + 2520 + /* Get SCSI command to be aborted */ 2521 + abort = (struct CommandList *) sc->host_scribble; 2522 + if (abort == NULL) { 2523 + dev_err(&h->pdev->dev, "%s FAILED, Command to abort is NULL.\n", 2524 + msg); 2525 + return FAILED; 2526 + } 2527 + 2528 + ml += sprintf(msg+ml, "Tag:0x%08x:%08x ", 2529 + abort->Header.Tag.upper, abort->Header.Tag.lower); 2530 + as = (struct scsi_cmnd *) abort->scsi_cmd; 2531 + if (as != NULL) 2532 + ml += sprintf(msg+ml, "Command:0x%x SN:0x%lx ", 2533 + as->cmnd[0], as->serial_number); 2534 + dev_dbg(&h->pdev->dev, "%s\n", msg); 2535 + dev_warn(&h->pdev->dev, "Abort request on C%d:B%d:T%d:L%d\n", 2536 + h->scsi_host->host_no, dev->bus, dev->target, dev->lun); 2537 + 2538 + /* Search reqQ to See if command is queued but not submitted, 2539 + * if so, complete the command with aborted status and remove 2540 + * it from the reqQ. 2541 + */ 2542 + found = hpsa_find_cmd_in_queue(h, sc, &h->reqQ); 2543 + if (found) { 2544 + found->err_info->CommandStatus = CMD_ABORTED; 2545 + finish_cmd(found); 2546 + dev_info(&h->pdev->dev, "%s Request SUCCEEDED (driver queue).\n", 2547 + msg); 2548 + return SUCCESS; 2549 + } 2550 + 2551 + /* not in reqQ, if also not in cmpQ, must have already completed */ 2552 + found = hpsa_find_cmd_in_queue(h, sc, &h->cmpQ); 2553 + if (!found) { 2554 + dev_dbg(&h->pdev->dev, "%s Request FAILED (not known to driver).\n", 2555 + msg); 2556 + return SUCCESS; 2557 + } 2558 + 2559 + /* 2560 + * Command is in flight, or possibly already completed 2561 + * by the firmware (but not to the scsi mid layer) but we can't 2562 + * distinguish which. Send the abort down. 2563 + */ 2564 + rc = hpsa_send_abort_both_ways(h, dev->scsi3addr, abort); 2565 + if (rc != 0) { 2566 + dev_dbg(&h->pdev->dev, "%s Request FAILED.\n", msg); 2567 + dev_warn(&h->pdev->dev, "FAILED abort on device C%d:B%d:T%d:L%d\n", 2568 + h->scsi_host->host_no, 2569 + dev->bus, dev->target, dev->lun); 2570 + return FAILED; 2571 + } 2572 + dev_info(&h->pdev->dev, "%s REQUEST SUCCEEDED.\n", msg); 2573 + 2574 + /* If the abort(s) above completed and actually aborted the 2575 + * command, then the command to be aborted should already be 2576 + * completed. If not, wait around a bit more to see if they 2577 + * manage to complete normally. 2578 + */ 2579 + #define ABORT_COMPLETE_WAIT_SECS 30 2580 + for (i = 0; i < ABORT_COMPLETE_WAIT_SECS * 10; i++) { 2581 + found = hpsa_find_cmd_in_queue(h, sc, &h->cmpQ); 2582 + if (!found) 2583 + return SUCCESS; 2584 + msleep(100); 2585 + } 2586 + dev_warn(&h->pdev->dev, "%s FAILED. Aborted command has not completed after %d seconds.\n", 2587 + msg, ABORT_COMPLETE_WAIT_SECS); 2588 + return FAILED; 2589 + } 2590 + 2591 + 2395 2592 /* 2396 2593 * For operations that cannot sleep, a command block is allocated at init, 2397 2594 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track ··· 2659 2346 int i; 2660 2347 union u64bit temp64; 2661 2348 dma_addr_t cmd_dma_handle, err_dma_handle; 2349 + unsigned long flags; 2662 2350 2351 + spin_lock_irqsave(&h->lock, flags); 2663 2352 do { 2664 2353 i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds); 2665 - if (i == h->nr_cmds) 2354 + if (i == h->nr_cmds) { 2355 + spin_unlock_irqrestore(&h->lock, flags); 2666 2356 return NULL; 2357 + } 2667 2358 } while (test_and_set_bit 2668 2359 (i & (BITS_PER_LONG - 1), 2669 2360 h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0); 2361 + h->nr_allocs++; 2362 + spin_unlock_irqrestore(&h->lock, flags); 2363 + 2670 2364 c = h->cmd_pool + i; 2671 2365 memset(c, 0, sizeof(*c)); 2672 2366 cmd_dma_handle = h->cmd_pool_dhandle ··· 2682 2362 memset(c->err_info, 0, sizeof(*c->err_info)); 2683 2363 err_dma_handle = h->errinfo_pool_dhandle 2684 2364 + i * sizeof(*c->err_info); 2685 - h->nr_allocs++; 2686 2365 2687 2366 c->cmdindex = i; 2688 2367 ··· 2737 2418 static void cmd_free(struct ctlr_info *h, struct CommandList *c) 2738 2419 { 2739 2420 int i; 2421 + unsigned long flags; 2740 2422 2741 2423 i = c - h->cmd_pool; 2424 + spin_lock_irqsave(&h->lock, flags); 2742 2425 clear_bit(i & (BITS_PER_LONG - 1), 2743 2426 h->cmd_pool_bits + (i / BITS_PER_LONG)); 2744 2427 h->nr_frees++; 2428 + spin_unlock_irqrestore(&h->lock, flags); 2745 2429 } 2746 2430 2747 2431 static void cmd_special_free(struct ctlr_info *h, struct CommandList *c) ··· 3188 2866 int cmd_type) 3189 2867 { 3190 2868 int pci_dir = XFER_NONE; 2869 + struct CommandList *a; /* for commands to be aborted */ 3191 2870 3192 2871 c->cmd_type = CMD_IOCTL_PEND; 3193 2872 c->Header.ReplyQueue = 0; ··· 3272 2949 c->Request.CDB[5] = 0x00; 3273 2950 c->Request.CDB[6] = 0x00; 3274 2951 c->Request.CDB[7] = 0x00; 2952 + break; 2953 + case HPSA_ABORT_MSG: 2954 + a = buff; /* point to command to be aborted */ 2955 + dev_dbg(&h->pdev->dev, "Abort Tag:0x%08x:%08x using request Tag:0x%08x:%08x\n", 2956 + a->Header.Tag.upper, a->Header.Tag.lower, 2957 + c->Header.Tag.upper, c->Header.Tag.lower); 2958 + c->Request.CDBLen = 16; 2959 + c->Request.Type.Type = TYPE_MSG; 2960 + c->Request.Type.Attribute = ATTR_SIMPLE; 2961 + c->Request.Type.Direction = XFER_WRITE; 2962 + c->Request.Timeout = 0; /* Don't time out */ 2963 + c->Request.CDB[0] = HPSA_TASK_MANAGEMENT; 2964 + c->Request.CDB[1] = HPSA_TMF_ABORT_TASK; 2965 + c->Request.CDB[2] = 0x00; /* reserved */ 2966 + c->Request.CDB[3] = 0x00; /* reserved */ 2967 + /* Tag to abort goes in CDB[4]-CDB[11] */ 2968 + c->Request.CDB[4] = a->Header.Tag.lower & 0xFF; 2969 + c->Request.CDB[5] = (a->Header.Tag.lower >> 8) & 0xFF; 2970 + c->Request.CDB[6] = (a->Header.Tag.lower >> 16) & 0xFF; 2971 + c->Request.CDB[7] = (a->Header.Tag.lower >> 24) & 0xFF; 2972 + c->Request.CDB[8] = a->Header.Tag.upper & 0xFF; 2973 + c->Request.CDB[9] = (a->Header.Tag.upper >> 8) & 0xFF; 2974 + c->Request.CDB[10] = (a->Header.Tag.upper >> 16) & 0xFF; 2975 + c->Request.CDB[11] = (a->Header.Tag.upper >> 24) & 0xFF; 2976 + c->Request.CDB[12] = 0x00; /* reserved */ 2977 + c->Request.CDB[13] = 0x00; /* reserved */ 2978 + c->Request.CDB[14] = 0x00; /* reserved */ 2979 + c->Request.CDB[15] = 0x00; /* reserved */ 3275 2980 break; 3276 - 3277 2981 default: 3278 2982 dev_warn(&h->pdev->dev, "unknown message type %d\n", 3279 2983 cmd); ··· 3348 2998 static void start_io(struct ctlr_info *h) 3349 2999 { 3350 3000 struct CommandList *c; 3001 + unsigned long flags; 3351 3002 3003 + spin_lock_irqsave(&h->lock, flags); 3352 3004 while (!list_empty(&h->reqQ)) { 3353 3005 c = list_entry(h->reqQ.next, struct CommandList, list); 3354 3006 /* can't do anything if fifo is full */ ··· 3363 3011 removeQ(c); 3364 3012 h->Qdepth--; 3365 3013 3366 - /* Tell the controller execute command */ 3367 - h->access.submit_command(h, c); 3368 - 3369 3014 /* Put job onto the completed Q */ 3370 3015 addQ(&h->cmpQ, c); 3016 + 3017 + /* Must increment commands_outstanding before unlocking 3018 + * and submitting to avoid race checking for fifo full 3019 + * condition. 3020 + */ 3021 + h->commands_outstanding++; 3022 + if (h->commands_outstanding > h->max_outstanding) 3023 + h->max_outstanding = h->commands_outstanding; 3024 + 3025 + /* Tell the controller execute command */ 3026 + spin_unlock_irqrestore(&h->lock, flags); 3027 + h->access.submit_command(h, c); 3028 + spin_lock_irqsave(&h->lock, flags); 3371 3029 } 3030 + spin_unlock_irqrestore(&h->lock, flags); 3372 3031 } 3373 3032 3374 - static inline unsigned long get_next_completion(struct ctlr_info *h) 3033 + static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q) 3375 3034 { 3376 - return h->access.command_completed(h); 3035 + return h->access.command_completed(h, q); 3377 3036 } 3378 3037 3379 3038 static inline bool interrupt_pending(struct ctlr_info *h) ··· 3408 3045 return 0; 3409 3046 } 3410 3047 3411 - static inline void finish_cmd(struct CommandList *c, u32 raw_tag) 3048 + static inline void finish_cmd(struct CommandList *c) 3412 3049 { 3050 + unsigned long flags; 3051 + 3052 + spin_lock_irqsave(&c->h->lock, flags); 3413 3053 removeQ(c); 3054 + spin_unlock_irqrestore(&c->h->lock, flags); 3055 + dial_up_lockup_detection_on_fw_flash_complete(c->h, c); 3414 3056 if (likely(c->cmd_type == CMD_SCSI)) 3415 3057 complete_scsi_command(c); 3416 3058 else if (c->cmd_type == CMD_IOCTL_PEND) ··· 3443 3075 } 3444 3076 3445 3077 /* process completion of an indexed ("direct lookup") command */ 3446 - static inline u32 process_indexed_cmd(struct ctlr_info *h, 3078 + static inline void process_indexed_cmd(struct ctlr_info *h, 3447 3079 u32 raw_tag) 3448 3080 { 3449 3081 u32 tag_index; 3450 3082 struct CommandList *c; 3451 3083 3452 3084 tag_index = hpsa_tag_to_index(raw_tag); 3453 - if (bad_tag(h, tag_index, raw_tag)) 3454 - return next_command(h); 3455 - c = h->cmd_pool + tag_index; 3456 - finish_cmd(c, raw_tag); 3457 - return next_command(h); 3085 + if (!bad_tag(h, tag_index, raw_tag)) { 3086 + c = h->cmd_pool + tag_index; 3087 + finish_cmd(c); 3088 + } 3458 3089 } 3459 3090 3460 3091 /* process completion of a non-indexed command */ 3461 - static inline u32 process_nonindexed_cmd(struct ctlr_info *h, 3092 + static inline void process_nonindexed_cmd(struct ctlr_info *h, 3462 3093 u32 raw_tag) 3463 3094 { 3464 3095 u32 tag; 3465 3096 struct CommandList *c = NULL; 3097 + unsigned long flags; 3466 3098 3467 3099 tag = hpsa_tag_discard_error_bits(h, raw_tag); 3100 + spin_lock_irqsave(&h->lock, flags); 3468 3101 list_for_each_entry(c, &h->cmpQ, list) { 3469 3102 if ((c->busaddr & 0xFFFFFFE0) == (tag & 0xFFFFFFE0)) { 3470 - finish_cmd(c, raw_tag); 3471 - return next_command(h); 3103 + spin_unlock_irqrestore(&h->lock, flags); 3104 + finish_cmd(c); 3105 + return; 3472 3106 } 3473 3107 } 3108 + spin_unlock_irqrestore(&h->lock, flags); 3474 3109 bad_tag(h, h->nr_cmds + 1, raw_tag); 3475 - return next_command(h); 3476 3110 } 3477 3111 3478 3112 /* Some controllers, like p400, will give us one interrupt ··· 3496 3126 return 1; 3497 3127 } 3498 3128 3499 - static irqreturn_t hpsa_intx_discard_completions(int irq, void *dev_id) 3129 + /* 3130 + * Convert &h->q[x] (passed to interrupt handlers) back to h. 3131 + * Relies on (h-q[x] == x) being true for x such that 3132 + * 0 <= x < MAX_REPLY_QUEUES. 3133 + */ 3134 + static struct ctlr_info *queue_to_hba(u8 *queue) 3500 3135 { 3501 - struct ctlr_info *h = dev_id; 3502 - unsigned long flags; 3136 + return container_of((queue - *queue), struct ctlr_info, q[0]); 3137 + } 3138 + 3139 + static irqreturn_t hpsa_intx_discard_completions(int irq, void *queue) 3140 + { 3141 + struct ctlr_info *h = queue_to_hba(queue); 3142 + u8 q = *(u8 *) queue; 3503 3143 u32 raw_tag; 3504 3144 3505 3145 if (ignore_bogus_interrupt(h)) ··· 3517 3137 3518 3138 if (interrupt_not_for_us(h)) 3519 3139 return IRQ_NONE; 3520 - spin_lock_irqsave(&h->lock, flags); 3521 3140 h->last_intr_timestamp = get_jiffies_64(); 3522 3141 while (interrupt_pending(h)) { 3523 - raw_tag = get_next_completion(h); 3142 + raw_tag = get_next_completion(h, q); 3524 3143 while (raw_tag != FIFO_EMPTY) 3525 - raw_tag = next_command(h); 3144 + raw_tag = next_command(h, q); 3526 3145 } 3527 - spin_unlock_irqrestore(&h->lock, flags); 3528 3146 return IRQ_HANDLED; 3529 3147 } 3530 3148 3531 - static irqreturn_t hpsa_msix_discard_completions(int irq, void *dev_id) 3149 + static irqreturn_t hpsa_msix_discard_completions(int irq, void *queue) 3532 3150 { 3533 - struct ctlr_info *h = dev_id; 3534 - unsigned long flags; 3151 + struct ctlr_info *h = queue_to_hba(queue); 3535 3152 u32 raw_tag; 3153 + u8 q = *(u8 *) queue; 3536 3154 3537 3155 if (ignore_bogus_interrupt(h)) 3538 3156 return IRQ_NONE; 3539 3157 3540 - spin_lock_irqsave(&h->lock, flags); 3541 3158 h->last_intr_timestamp = get_jiffies_64(); 3542 - raw_tag = get_next_completion(h); 3159 + raw_tag = get_next_completion(h, q); 3543 3160 while (raw_tag != FIFO_EMPTY) 3544 - raw_tag = next_command(h); 3545 - spin_unlock_irqrestore(&h->lock, flags); 3161 + raw_tag = next_command(h, q); 3546 3162 return IRQ_HANDLED; 3547 3163 } 3548 3164 3549 - static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id) 3165 + static irqreturn_t do_hpsa_intr_intx(int irq, void *queue) 3550 3166 { 3551 - struct ctlr_info *h = dev_id; 3552 - unsigned long flags; 3167 + struct ctlr_info *h = queue_to_hba((u8 *) queue); 3553 3168 u32 raw_tag; 3169 + u8 q = *(u8 *) queue; 3554 3170 3555 3171 if (interrupt_not_for_us(h)) 3556 3172 return IRQ_NONE; 3557 - spin_lock_irqsave(&h->lock, flags); 3558 3173 h->last_intr_timestamp = get_jiffies_64(); 3559 3174 while (interrupt_pending(h)) { 3560 - raw_tag = get_next_completion(h); 3175 + raw_tag = get_next_completion(h, q); 3561 3176 while (raw_tag != FIFO_EMPTY) { 3562 - if (hpsa_tag_contains_index(raw_tag)) 3563 - raw_tag = process_indexed_cmd(h, raw_tag); 3177 + if (likely(hpsa_tag_contains_index(raw_tag))) 3178 + process_indexed_cmd(h, raw_tag); 3564 3179 else 3565 - raw_tag = process_nonindexed_cmd(h, raw_tag); 3180 + process_nonindexed_cmd(h, raw_tag); 3181 + raw_tag = next_command(h, q); 3566 3182 } 3567 3183 } 3568 - spin_unlock_irqrestore(&h->lock, flags); 3569 3184 return IRQ_HANDLED; 3570 3185 } 3571 3186 3572 - static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id) 3187 + static irqreturn_t do_hpsa_intr_msi(int irq, void *queue) 3573 3188 { 3574 - struct ctlr_info *h = dev_id; 3575 - unsigned long flags; 3189 + struct ctlr_info *h = queue_to_hba(queue); 3576 3190 u32 raw_tag; 3191 + u8 q = *(u8 *) queue; 3577 3192 3578 - spin_lock_irqsave(&h->lock, flags); 3579 3193 h->last_intr_timestamp = get_jiffies_64(); 3580 - raw_tag = get_next_completion(h); 3194 + raw_tag = get_next_completion(h, q); 3581 3195 while (raw_tag != FIFO_EMPTY) { 3582 - if (hpsa_tag_contains_index(raw_tag)) 3583 - raw_tag = process_indexed_cmd(h, raw_tag); 3196 + if (likely(hpsa_tag_contains_index(raw_tag))) 3197 + process_indexed_cmd(h, raw_tag); 3584 3198 else 3585 - raw_tag = process_nonindexed_cmd(h, raw_tag); 3199 + process_nonindexed_cmd(h, raw_tag); 3200 + raw_tag = next_command(h, q); 3586 3201 } 3587 - spin_unlock_irqrestore(&h->lock, flags); 3588 3202 return IRQ_HANDLED; 3589 3203 } 3590 3204 ··· 4012 3638 static void __devinit hpsa_interrupt_mode(struct ctlr_info *h) 4013 3639 { 4014 3640 #ifdef CONFIG_PCI_MSI 4015 - int err; 4016 - struct msix_entry hpsa_msix_entries[4] = { {0, 0}, {0, 1}, 4017 - {0, 2}, {0, 3} 4018 - }; 3641 + int err, i; 3642 + struct msix_entry hpsa_msix_entries[MAX_REPLY_QUEUES]; 3643 + 3644 + for (i = 0; i < MAX_REPLY_QUEUES; i++) { 3645 + hpsa_msix_entries[i].vector = 0; 3646 + hpsa_msix_entries[i].entry = i; 3647 + } 4019 3648 4020 3649 /* Some boards advertise MSI but don't really support it */ 4021 3650 if ((h->board_id == 0x40700E11) || (h->board_id == 0x40800E11) || ··· 4026 3649 goto default_int_mode; 4027 3650 if (pci_find_capability(h->pdev, PCI_CAP_ID_MSIX)) { 4028 3651 dev_info(&h->pdev->dev, "MSIX\n"); 4029 - err = pci_enable_msix(h->pdev, hpsa_msix_entries, 4); 3652 + err = pci_enable_msix(h->pdev, hpsa_msix_entries, 3653 + MAX_REPLY_QUEUES); 4030 3654 if (!err) { 4031 - h->intr[0] = hpsa_msix_entries[0].vector; 4032 - h->intr[1] = hpsa_msix_entries[1].vector; 4033 - h->intr[2] = hpsa_msix_entries[2].vector; 4034 - h->intr[3] = hpsa_msix_entries[3].vector; 3655 + for (i = 0; i < MAX_REPLY_QUEUES; i++) 3656 + h->intr[i] = hpsa_msix_entries[i].vector; 4035 3657 h->msix_vector = 1; 4036 3658 return; 4037 3659 } ··· 4079 3703 return -ENODEV; 4080 3704 } 4081 3705 return ARRAY_SIZE(products) - 1; /* generic unknown smart array */ 4082 - } 4083 - 4084 - static inline bool hpsa_board_disabled(struct pci_dev *pdev) 4085 - { 4086 - u16 command; 4087 - 4088 - (void) pci_read_config_word(pdev, PCI_COMMAND, &command); 4089 - return ((command & PCI_COMMAND_MEMORY) == 0); 4090 3706 } 4091 3707 4092 3708 static int __devinit hpsa_pci_find_memory_BAR(struct pci_dev *pdev, ··· 4206 3838 h->maxsgentries = 31; /* default to traditional values */ 4207 3839 h->chainsize = 0; 4208 3840 } 3841 + 3842 + /* Find out what task management functions are supported and cache */ 3843 + h->TMFSupportFlags = readl(&(h->cfgtable->TMFSupportFlags)); 4209 3844 } 4210 3845 4211 3846 static inline bool hpsa_CISS_signature_present(struct ctlr_info *h) 4212 3847 { 4213 - if ((readb(&h->cfgtable->Signature[0]) != 'C') || 4214 - (readb(&h->cfgtable->Signature[1]) != 'I') || 4215 - (readb(&h->cfgtable->Signature[2]) != 'S') || 4216 - (readb(&h->cfgtable->Signature[3]) != 'S')) { 3848 + if (!check_signature(h->cfgtable->Signature, "CISS", 4)) { 4217 3849 dev_warn(&h->pdev->dev, "not a valid CISS config table\n"); 4218 3850 return false; 4219 3851 } ··· 4300 3932 h->product_name = products[prod_index].product_name; 4301 3933 h->access = *(products[prod_index].access); 4302 3934 4303 - if (hpsa_board_disabled(h->pdev)) { 4304 - dev_warn(&h->pdev->dev, "controller appears to be disabled\n"); 4305 - return -ENODEV; 4306 - } 4307 - 4308 3935 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S | 4309 3936 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); 4310 3937 ··· 4308 3945 dev_warn(&h->pdev->dev, "unable to enable PCI device\n"); 4309 3946 return err; 4310 3947 } 3948 + 3949 + /* Enable bus mastering (pci_disable_device may disable this) */ 3950 + pci_set_master(h->pdev); 4311 3951 4312 3952 err = pci_request_regions(h->pdev, HPSA); 4313 3953 if (err) { ··· 4353 3987 iounmap(h->cfgtable); 4354 3988 if (h->vaddr) 4355 3989 iounmap(h->vaddr); 4356 - /* 4357 - * Deliberately omit pci_disable_device(): it does something nasty to 4358 - * Smart Array controllers that pci_enable_device does not undo 4359 - */ 3990 + pci_disable_device(h->pdev); 4360 3991 pci_release_regions(h->pdev); 4361 3992 return err; 4362 3993 } ··· 4444 4081 irqreturn_t (*msixhandler)(int, void *), 4445 4082 irqreturn_t (*intxhandler)(int, void *)) 4446 4083 { 4447 - int rc; 4084 + int rc, i; 4448 4085 4449 - if (h->msix_vector || h->msi_vector) 4450 - rc = request_irq(h->intr[h->intr_mode], msixhandler, 4451 - 0, h->devname, h); 4452 - else 4453 - rc = request_irq(h->intr[h->intr_mode], intxhandler, 4454 - IRQF_SHARED, h->devname, h); 4086 + /* 4087 + * initialize h->q[x] = x so that interrupt handlers know which 4088 + * queue to process. 4089 + */ 4090 + for (i = 0; i < MAX_REPLY_QUEUES; i++) 4091 + h->q[i] = (u8) i; 4092 + 4093 + if (h->intr_mode == PERF_MODE_INT && h->msix_vector) { 4094 + /* If performant mode and MSI-X, use multiple reply queues */ 4095 + for (i = 0; i < MAX_REPLY_QUEUES; i++) 4096 + rc = request_irq(h->intr[i], msixhandler, 4097 + 0, h->devname, 4098 + &h->q[i]); 4099 + } else { 4100 + /* Use single reply pool */ 4101 + if (h->msix_vector || h->msi_vector) { 4102 + rc = request_irq(h->intr[h->intr_mode], 4103 + msixhandler, 0, h->devname, 4104 + &h->q[h->intr_mode]); 4105 + } else { 4106 + rc = request_irq(h->intr[h->intr_mode], 4107 + intxhandler, IRQF_SHARED, h->devname, 4108 + &h->q[h->intr_mode]); 4109 + } 4110 + } 4455 4111 if (rc) { 4456 4112 dev_err(&h->pdev->dev, "unable to get irq %d for %s\n", 4457 4113 h->intr[h->intr_mode], h->devname); ··· 4503 4121 return 0; 4504 4122 } 4505 4123 4124 + static void free_irqs(struct ctlr_info *h) 4125 + { 4126 + int i; 4127 + 4128 + if (!h->msix_vector || h->intr_mode != PERF_MODE_INT) { 4129 + /* Single reply queue, only one irq to free */ 4130 + i = h->intr_mode; 4131 + free_irq(h->intr[i], &h->q[i]); 4132 + return; 4133 + } 4134 + 4135 + for (i = 0; i < MAX_REPLY_QUEUES; i++) 4136 + free_irq(h->intr[i], &h->q[i]); 4137 + } 4138 + 4139 + static void hpsa_free_irqs_and_disable_msix(struct ctlr_info *h) 4140 + { 4141 + free_irqs(h); 4142 + #ifdef CONFIG_PCI_MSI 4143 + if (h->msix_vector) { 4144 + if (h->pdev->msix_enabled) 4145 + pci_disable_msix(h->pdev); 4146 + } else if (h->msi_vector) { 4147 + if (h->pdev->msi_enabled) 4148 + pci_disable_msi(h->pdev); 4149 + } 4150 + #endif /* CONFIG_PCI_MSI */ 4151 + } 4152 + 4506 4153 static void hpsa_undo_allocations_after_kdump_soft_reset(struct ctlr_info *h) 4507 4154 { 4508 - free_irq(h->intr[h->intr_mode], h); 4509 - #ifdef CONFIG_PCI_MSI 4510 - if (h->msix_vector) 4511 - pci_disable_msix(h->pdev); 4512 - else if (h->msi_vector) 4513 - pci_disable_msi(h->pdev); 4514 - #endif /* CONFIG_PCI_MSI */ 4155 + hpsa_free_irqs_and_disable_msix(h); 4515 4156 hpsa_free_sg_chain_blocks(h); 4516 4157 hpsa_free_cmd_pool(h); 4517 4158 kfree(h->blockFetchTable); ··· 4570 4165 while (!list_empty(list)) { 4571 4166 c = list_entry(list->next, struct CommandList, list); 4572 4167 c->err_info->CommandStatus = CMD_HARDWARE_ERR; 4573 - finish_cmd(c, c->Header.Tag.lower); 4168 + finish_cmd(c); 4574 4169 } 4575 4170 } 4576 4171 ··· 4593 4188 spin_unlock_irqrestore(&h->lock, flags); 4594 4189 } 4595 4190 4596 - #define HEARTBEAT_SAMPLE_INTERVAL (10 * HZ) 4597 - #define HEARTBEAT_CHECK_MINIMUM_INTERVAL (HEARTBEAT_SAMPLE_INTERVAL / 2) 4598 - 4599 4191 static void detect_controller_lockup(struct ctlr_info *h) 4600 4192 { 4601 4193 u64 now; ··· 4603 4201 now = get_jiffies_64(); 4604 4202 /* If we've received an interrupt recently, we're ok. */ 4605 4203 if (time_after64(h->last_intr_timestamp + 4606 - (HEARTBEAT_CHECK_MINIMUM_INTERVAL), now)) 4204 + (h->heartbeat_sample_interval), now)) 4607 4205 return; 4608 4206 4609 4207 /* ··· 4612 4210 * otherwise don't care about signals in this thread. 4613 4211 */ 4614 4212 if (time_after64(h->last_heartbeat_timestamp + 4615 - (HEARTBEAT_CHECK_MINIMUM_INTERVAL), now)) 4213 + (h->heartbeat_sample_interval), now)) 4616 4214 return; 4617 4215 4618 4216 /* If heartbeat has not changed since we last looked, we're not ok. */ ··· 4654 4252 { 4655 4253 unsigned long flags; 4656 4254 4255 + h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; 4657 4256 spin_lock_irqsave(&lockup_detector_lock, flags); 4658 4257 list_add_tail(&h->lockup_list, &hpsa_ctlr_list); 4659 4258 spin_unlock_irqrestore(&lockup_detector_lock, flags); ··· 4794 4391 spin_lock_irqsave(&h->lock, flags); 4795 4392 h->access.set_intr_mask(h, HPSA_INTR_OFF); 4796 4393 spin_unlock_irqrestore(&h->lock, flags); 4797 - free_irq(h->intr[h->intr_mode], h); 4394 + free_irqs(h); 4798 4395 rc = hpsa_request_irq(h, hpsa_msix_discard_completions, 4799 4396 hpsa_intx_discard_completions); 4800 4397 if (rc) { ··· 4844 4441 clean4: 4845 4442 hpsa_free_sg_chain_blocks(h); 4846 4443 hpsa_free_cmd_pool(h); 4847 - free_irq(h->intr[h->intr_mode], h); 4444 + free_irqs(h); 4848 4445 clean2: 4849 4446 clean1: 4850 4447 kfree(h); ··· 4887 4484 */ 4888 4485 hpsa_flush_cache(h); 4889 4486 h->access.set_intr_mask(h, HPSA_INTR_OFF); 4890 - free_irq(h->intr[h->intr_mode], h); 4891 - #ifdef CONFIG_PCI_MSI 4892 - if (h->msix_vector) 4893 - pci_disable_msix(h->pdev); 4894 - else if (h->msi_vector) 4895 - pci_disable_msi(h->pdev); 4896 - #endif /* CONFIG_PCI_MSI */ 4487 + hpsa_free_irqs_and_disable_msix(h); 4897 4488 } 4898 4489 4899 4490 static void __devexit hpsa_free_device_info(struct ctlr_info *h) ··· 4926 4529 kfree(h->cmd_pool_bits); 4927 4530 kfree(h->blockFetchTable); 4928 4531 kfree(h->hba_inquiry_data); 4929 - /* 4930 - * Deliberately omit pci_disable_device(): it does something nasty to 4931 - * Smart Array controllers that pci_enable_device does not undo 4932 - */ 4532 + pci_disable_device(pdev); 4933 4533 pci_release_regions(pdev); 4934 4534 pci_set_drvdata(pdev, NULL); 4935 4535 kfree(h); ··· 5021 4627 * 10 = 6 s/g entry or 24k 5022 4628 */ 5023 4629 5024 - h->reply_pool_wraparound = 1; /* spec: init to 1 */ 5025 - 5026 4630 /* Controller spec: zero out this buffer. */ 5027 4631 memset(h->reply_pool, 0, h->reply_pool_size); 5028 - h->reply_pool_head = h->reply_pool; 5029 4632 5030 4633 bft[7] = SG_ENTRIES_IN_CMD + 4; 5031 4634 calc_bucket_map(bft, ARRAY_SIZE(bft), ··· 5032 4641 5033 4642 /* size of controller ring buffer */ 5034 4643 writel(h->max_commands, &h->transtable->RepQSize); 5035 - writel(1, &h->transtable->RepQCount); 4644 + writel(h->nreply_queues, &h->transtable->RepQCount); 5036 4645 writel(0, &h->transtable->RepQCtrAddrLow32); 5037 4646 writel(0, &h->transtable->RepQCtrAddrHigh32); 5038 - writel(h->reply_pool_dhandle, &h->transtable->RepQAddr0Low32); 5039 - writel(0, &h->transtable->RepQAddr0High32); 5040 - writel(CFGTBL_Trans_Performant | use_short_tags, 4647 + 4648 + for (i = 0; i < h->nreply_queues; i++) { 4649 + writel(0, &h->transtable->RepQAddr[i].upper); 4650 + writel(h->reply_pool_dhandle + 4651 + (h->max_commands * sizeof(u64) * i), 4652 + &h->transtable->RepQAddr[i].lower); 4653 + } 4654 + 4655 + writel(CFGTBL_Trans_Performant | use_short_tags | 4656 + CFGTBL_Trans_enable_directed_msix, 5041 4657 &(h->cfgtable->HostWrite.TransportRequest)); 5042 4658 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); 5043 4659 hpsa_wait_for_mode_change_ack(h); ··· 5062 4664 static __devinit void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h) 5063 4665 { 5064 4666 u32 trans_support; 4667 + int i; 5065 4668 5066 4669 if (hpsa_simple_mode) 5067 4670 return; ··· 5071 4672 if (!(trans_support & PERFORMANT_MODE)) 5072 4673 return; 5073 4674 4675 + h->nreply_queues = h->msix_vector ? MAX_REPLY_QUEUES : 1; 5074 4676 hpsa_get_max_perf_mode_cmds(h); 5075 4677 /* Performant mode ring buffer and supporting data structures */ 5076 - h->reply_pool_size = h->max_commands * sizeof(u64); 4678 + h->reply_pool_size = h->max_commands * sizeof(u64) * h->nreply_queues; 5077 4679 h->reply_pool = pci_alloc_consistent(h->pdev, h->reply_pool_size, 5078 4680 &(h->reply_pool_dhandle)); 4681 + 4682 + for (i = 0; i < h->nreply_queues; i++) { 4683 + h->reply_queue[i].head = &h->reply_pool[h->max_commands * i]; 4684 + h->reply_queue[i].size = h->max_commands; 4685 + h->reply_queue[i].wraparound = 1; /* spec: init to 1 */ 4686 + h->reply_queue[i].current_entry = 0; 4687 + } 5079 4688 5080 4689 /* Need a block fetch table for performant mode */ 5081 4690 h->blockFetchTable = kmalloc(((SG_ENTRIES_IN_CMD + 1) *
+60 -25
drivers/scsi/hpsa.h
··· 34 34 void (*set_intr_mask)(struct ctlr_info *h, unsigned long val); 35 35 unsigned long (*fifo_full)(struct ctlr_info *h); 36 36 bool (*intr_pending)(struct ctlr_info *h); 37 - unsigned long (*command_completed)(struct ctlr_info *h); 37 + unsigned long (*command_completed)(struct ctlr_info *h, u8 q); 38 38 }; 39 39 40 40 struct hpsa_scsi_dev_t { ··· 46 46 unsigned char vendor[8]; /* bytes 8-15 of inquiry data */ 47 47 unsigned char model[16]; /* bytes 16-31 of inquiry data */ 48 48 unsigned char raid_level; /* from inquiry page 0xC1 */ 49 + }; 50 + 51 + struct reply_pool { 52 + u64 *head; 53 + size_t size; 54 + u8 wraparound; 55 + u32 current_entry; 49 56 }; 50 57 51 58 struct ctlr_info { ··· 75 68 # define DOORBELL_INT 1 76 69 # define SIMPLE_MODE_INT 2 77 70 # define MEMQ_MODE_INT 3 78 - unsigned int intr[4]; 71 + unsigned int intr[MAX_REPLY_QUEUES]; 79 72 unsigned int msix_vector; 80 73 unsigned int msi_vector; 81 74 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */ ··· 85 78 struct list_head reqQ; 86 79 struct list_head cmpQ; 87 80 unsigned int Qdepth; 88 - unsigned int maxQsinceinit; 89 81 unsigned int maxSG; 90 82 spinlock_t lock; 91 83 int maxsgentries; ··· 117 111 unsigned long transMethod; 118 112 119 113 /* 120 - * Performant mode completion buffer 114 + * Performant mode completion buffers 121 115 */ 122 116 u64 *reply_pool; 123 - dma_addr_t reply_pool_dhandle; 124 - u64 *reply_pool_head; 125 117 size_t reply_pool_size; 126 - unsigned char reply_pool_wraparound; 118 + struct reply_pool reply_queue[MAX_REPLY_QUEUES]; 119 + u8 nreply_queues; 120 + dma_addr_t reply_pool_dhandle; 127 121 u32 *blockFetchTable; 128 122 unsigned char *hba_inquiry_data; 129 123 u64 last_intr_timestamp; 130 124 u32 last_heartbeat; 131 125 u64 last_heartbeat_timestamp; 126 + u32 heartbeat_sample_interval; 127 + atomic_t firmware_flash_in_progress; 132 128 u32 lockup_detected; 133 129 struct list_head lockup_list; 130 + /* Address of h->q[x] is passed to intr handler to know which queue */ 131 + u8 q[MAX_REPLY_QUEUES]; 132 + u32 TMFSupportFlags; /* cache what task mgmt funcs are supported. */ 133 + #define HPSATMF_BITS_SUPPORTED (1 << 0) 134 + #define HPSATMF_PHYS_LUN_RESET (1 << 1) 135 + #define HPSATMF_PHYS_NEX_RESET (1 << 2) 136 + #define HPSATMF_PHYS_TASK_ABORT (1 << 3) 137 + #define HPSATMF_PHYS_TSET_ABORT (1 << 4) 138 + #define HPSATMF_PHYS_CLEAR_ACA (1 << 5) 139 + #define HPSATMF_PHYS_CLEAR_TSET (1 << 6) 140 + #define HPSATMF_PHYS_QRY_TASK (1 << 7) 141 + #define HPSATMF_PHYS_QRY_TSET (1 << 8) 142 + #define HPSATMF_PHYS_QRY_ASYNC (1 << 9) 143 + #define HPSATMF_MASK_SUPPORTED (1 << 16) 144 + #define HPSATMF_LOG_LUN_RESET (1 << 17) 145 + #define HPSATMF_LOG_NEX_RESET (1 << 18) 146 + #define HPSATMF_LOG_TASK_ABORT (1 << 19) 147 + #define HPSATMF_LOG_TSET_ABORT (1 << 20) 148 + #define HPSATMF_LOG_CLEAR_ACA (1 << 21) 149 + #define HPSATMF_LOG_CLEAR_TSET (1 << 22) 150 + #define HPSATMF_LOG_QRY_TASK (1 << 23) 151 + #define HPSATMF_LOG_QRY_TSET (1 << 24) 152 + #define HPSATMF_LOG_QRY_ASYNC (1 << 25) 134 153 }; 135 154 #define HPSA_ABORT_MSG 0 136 155 #define HPSA_DEVICE_RESET_MSG 1 ··· 247 216 c->Header.Tag.lower); 248 217 writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET); 249 218 (void) readl(h->vaddr + SA5_SCRATCHPAD_OFFSET); 250 - h->commands_outstanding++; 251 - if (h->commands_outstanding > h->max_outstanding) 252 - h->max_outstanding = h->commands_outstanding; 253 219 } 254 220 255 221 /* ··· 282 254 } 283 255 } 284 256 285 - static unsigned long SA5_performant_completed(struct ctlr_info *h) 257 + static unsigned long SA5_performant_completed(struct ctlr_info *h, u8 q) 286 258 { 287 - unsigned long register_value = FIFO_EMPTY; 259 + struct reply_pool *rq = &h->reply_queue[q]; 260 + unsigned long flags, register_value = FIFO_EMPTY; 288 261 289 - /* flush the controller write of the reply queue by reading 290 - * outbound doorbell status register. 291 - */ 292 - register_value = readl(h->vaddr + SA5_OUTDB_STATUS); 293 262 /* msi auto clears the interrupt pending bit. */ 294 263 if (!(h->msi_vector || h->msix_vector)) { 264 + /* flush the controller write of the reply queue by reading 265 + * outbound doorbell status register. 266 + */ 267 + register_value = readl(h->vaddr + SA5_OUTDB_STATUS); 295 268 writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR); 296 269 /* Do a read in order to flush the write to the controller 297 270 * (as per spec.) ··· 300 271 register_value = readl(h->vaddr + SA5_OUTDB_STATUS); 301 272 } 302 273 303 - if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) { 304 - register_value = *(h->reply_pool_head); 305 - (h->reply_pool_head)++; 274 + if ((rq->head[rq->current_entry] & 1) == rq->wraparound) { 275 + register_value = rq->head[rq->current_entry]; 276 + rq->current_entry++; 277 + spin_lock_irqsave(&h->lock, flags); 306 278 h->commands_outstanding--; 279 + spin_unlock_irqrestore(&h->lock, flags); 307 280 } else { 308 281 register_value = FIFO_EMPTY; 309 282 } 310 283 /* Check for wraparound */ 311 - if (h->reply_pool_head == (h->reply_pool + h->max_commands)) { 312 - h->reply_pool_head = h->reply_pool; 313 - h->reply_pool_wraparound ^= 1; 284 + if (rq->current_entry == h->max_commands) { 285 + rq->current_entry = 0; 286 + rq->wraparound ^= 1; 314 287 } 315 - 316 288 return register_value; 317 289 } 318 290 ··· 333 303 * returns value read from hardware. 334 304 * returns FIFO_EMPTY if there is nothing to read 335 305 */ 336 - static unsigned long SA5_completed(struct ctlr_info *h) 306 + static unsigned long SA5_completed(struct ctlr_info *h, 307 + __attribute__((unused)) u8 q) 337 308 { 338 309 unsigned long register_value 339 310 = readl(h->vaddr + SA5_REPLY_PORT_OFFSET); 311 + unsigned long flags; 340 312 341 - if (register_value != FIFO_EMPTY) 313 + if (register_value != FIFO_EMPTY) { 314 + spin_lock_irqsave(&h->lock, flags); 342 315 h->commands_outstanding--; 316 + spin_unlock_irqrestore(&h->lock, flags); 317 + } 343 318 344 319 #ifdef HPSA_DEBUG 345 320 if (register_value != FIFO_EMPTY)
+34 -3
drivers/scsi/hpsa_cmd.h
··· 82 82 #define TYPE_CMD 0x00 83 83 #define TYPE_MSG 0x01 84 84 85 + /* Message Types */ 86 + #define HPSA_TASK_MANAGEMENT 0x00 87 + #define HPSA_RESET 0x01 88 + #define HPSA_SCAN 0x02 89 + #define HPSA_NOOP 0x03 90 + 91 + #define HPSA_CTLR_RESET_TYPE 0x00 92 + #define HPSA_BUS_RESET_TYPE 0x01 93 + #define HPSA_TARGET_RESET_TYPE 0x03 94 + #define HPSA_LUN_RESET_TYPE 0x04 95 + #define HPSA_NEXUS_RESET_TYPE 0x05 96 + 97 + /* Task Management Functions */ 98 + #define HPSA_TMF_ABORT_TASK 0x00 99 + #define HPSA_TMF_ABORT_TASK_SET 0x01 100 + #define HPSA_TMF_CLEAR_ACA 0x02 101 + #define HPSA_TMF_CLEAR_TASK_SET 0x03 102 + #define HPSA_TMF_QUERY_TASK 0x04 103 + #define HPSA_TMF_QUERY_TASK_SET 0x05 104 + #define HPSA_TMF_QUERY_ASYNCEVENT 0x06 105 + 106 + 107 + 85 108 /* config space register offsets */ 86 109 #define CFG_VENDORID 0x00 87 110 #define CFG_DEVICEID 0x02 ··· 129 106 #define CFGTBL_Trans_Simple 0x00000002l 130 107 #define CFGTBL_Trans_Performant 0x00000004l 131 108 #define CFGTBL_Trans_use_short_tags 0x20000000l 109 + #define CFGTBL_Trans_enable_directed_msix (1 << 30) 132 110 133 111 #define CFGTBL_BusType_Ultra2 0x00000001l 134 112 #define CFGTBL_BusType_Ultra3 0x00000002l ··· 186 162 #define BMIC_WRITE 0x27 187 163 #define BMIC_CACHE_FLUSH 0xc2 188 164 #define HPSA_CACHE_FLUSH 0x01 /* C2 was already being used by HPSA */ 165 + #define BMIC_FLASH_FIRMWARE 0xF7 189 166 190 167 /* Command List Structure */ 191 168 union SCSI3Addr { ··· 362 337 u32 MaxPhysicalDevices; 363 338 u32 MaxPhysicalDrivesPerLogicalUnit; 364 339 u32 MaxPerformantModeCommands; 365 - u8 reserved[0x78 - 0x58]; 340 + u32 MaxBlockFetch; 341 + u32 PowerConservationSupport; 342 + u32 PowerConservationEnable; 343 + u32 TMFSupportFlags; 344 + u8 TMFTagMask[8]; 345 + u8 reserved[0x78 - 0x70]; 366 346 u32 misc_fw_support; /* offset 0x78 */ 367 347 #define MISC_FW_DOORBELL_RESET (0x02) 368 348 #define MISC_FW_DOORBELL_RESET2 (0x010) 369 349 u8 driver_version[32]; 350 + 370 351 }; 371 352 372 353 #define NUM_BLOCKFETCH_ENTRIES 8 ··· 382 351 u32 RepQCount; 383 352 u32 RepQCtrAddrLow32; 384 353 u32 RepQCtrAddrHigh32; 385 - u32 RepQAddr0Low32; 386 - u32 RepQAddr0High32; 354 + #define MAX_REPLY_QUEUES 8 355 + struct vals32 RepQAddr[MAX_REPLY_QUEUES]; 387 356 }; 388 357 389 358 struct hpsa_pci_info {
+235 -470
drivers/scsi/isci/host.c
··· 192 192 193 193 static bool sci_controller_isr(struct isci_host *ihost) 194 194 { 195 - if (sci_controller_completion_queue_has_entries(ihost)) { 195 + if (sci_controller_completion_queue_has_entries(ihost)) 196 196 return true; 197 - } else { 198 - /* 199 - * we have a spurious interrupt it could be that we have already 200 - * emptied the completion queue from a previous interrupt */ 201 - writel(SMU_ISR_COMPLETION, &ihost->smu_registers->interrupt_status); 202 197 203 - /* 204 - * There is a race in the hardware that could cause us not to be notified 205 - * of an interrupt completion if we do not take this step. We will mask 206 - * then unmask the interrupts so if there is another interrupt pending 207 - * the clearing of the interrupt source we get the next interrupt message. */ 198 + /* we have a spurious interrupt it could be that we have already 199 + * emptied the completion queue from a previous interrupt 200 + * FIXME: really!? 201 + */ 202 + writel(SMU_ISR_COMPLETION, &ihost->smu_registers->interrupt_status); 203 + 204 + /* There is a race in the hardware that could cause us not to be 205 + * notified of an interrupt completion if we do not take this 206 + * step. We will mask then unmask the interrupts so if there is 207 + * another interrupt pending the clearing of the interrupt 208 + * source we get the next interrupt message. 209 + */ 210 + spin_lock(&ihost->scic_lock); 211 + if (test_bit(IHOST_IRQ_ENABLED, &ihost->flags)) { 208 212 writel(0xFF000000, &ihost->smu_registers->interrupt_mask); 209 213 writel(0, &ihost->smu_registers->interrupt_mask); 210 214 } 215 + spin_unlock(&ihost->scic_lock); 211 216 212 217 return false; 213 218 } ··· 647 642 if (completion_status != SCI_SUCCESS) 648 643 dev_info(&ihost->pdev->dev, 649 644 "controller start timed out, continuing...\n"); 650 - isci_host_change_state(ihost, isci_ready); 651 645 clear_bit(IHOST_START_PENDING, &ihost->flags); 652 646 wake_up(&ihost->eventq); 653 647 } ··· 661 657 662 658 sas_drain_work(ha); 663 659 664 - dev_dbg(&ihost->pdev->dev, 665 - "%s: ihost->status = %d, time = %ld\n", 666 - __func__, isci_host_get_state(ihost), time); 667 - 668 660 return 1; 669 - 670 661 } 671 662 672 663 /** ··· 703 704 704 705 static void sci_controller_enable_interrupts(struct isci_host *ihost) 705 706 { 706 - BUG_ON(ihost->smu_registers == NULL); 707 + set_bit(IHOST_IRQ_ENABLED, &ihost->flags); 707 708 writel(0, &ihost->smu_registers->interrupt_mask); 708 709 } 709 710 710 711 void sci_controller_disable_interrupts(struct isci_host *ihost) 711 712 { 712 - BUG_ON(ihost->smu_registers == NULL); 713 + clear_bit(IHOST_IRQ_ENABLED, &ihost->flags); 713 714 writel(0xffffffff, &ihost->smu_registers->interrupt_mask); 715 + readl(&ihost->smu_registers->interrupt_mask); /* flush */ 714 716 } 715 717 716 718 static void sci_controller_enable_port_task_scheduler(struct isci_host *ihost) ··· 822 822 &ihost->scu_registers->sdma.unsolicited_frame_put_pointer); 823 823 } 824 824 825 - static void sci_controller_transition_to_ready(struct isci_host *ihost, enum sci_status status) 825 + void sci_controller_transition_to_ready(struct isci_host *ihost, enum sci_status status) 826 826 { 827 827 if (ihost->sm.current_state_id == SCIC_STARTING) { 828 828 /* ··· 849 849 case SCI_PHY_SUB_AWAIT_SATA_POWER: 850 850 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN: 851 851 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN: 852 + case SCI_PHY_SUB_AWAIT_OSSP_EN: 852 853 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: 853 854 case SCI_PHY_SUB_FINAL: 854 855 return true; 855 856 default: 856 857 return false; 857 858 } 859 + } 860 + 861 + bool is_controller_start_complete(struct isci_host *ihost) 862 + { 863 + int i; 864 + 865 + for (i = 0; i < SCI_MAX_PHYS; i++) { 866 + struct isci_phy *iphy = &ihost->phys[i]; 867 + u32 state = iphy->sm.current_state_id; 868 + 869 + /* in apc mode we need to check every phy, in 870 + * mpc mode we only need to check phys that have 871 + * been configured into a port 872 + */ 873 + if (is_port_config_apc(ihost)) 874 + /* pass */; 875 + else if (!phy_get_non_dummy_port(iphy)) 876 + continue; 877 + 878 + /* The controller start operation is complete iff: 879 + * - all links have been given an opportunity to start 880 + * - have no indication of a connected device 881 + * - have an indication of a connected device and it has 882 + * finished the link training process. 883 + */ 884 + if ((iphy->is_in_link_training == false && state == SCI_PHY_INITIAL) || 885 + (iphy->is_in_link_training == false && state == SCI_PHY_STOPPED) || 886 + (iphy->is_in_link_training == true && is_phy_starting(iphy)) || 887 + (ihost->port_agent.phy_ready_mask != ihost->port_agent.phy_configured_mask)) 888 + return false; 889 + } 890 + 891 + return true; 858 892 } 859 893 860 894 /** ··· 911 877 return status; 912 878 913 879 if (ihost->next_phy_to_start >= SCI_MAX_PHYS) { 914 - bool is_controller_start_complete = true; 915 - u32 state; 916 - u8 index; 917 - 918 - for (index = 0; index < SCI_MAX_PHYS; index++) { 919 - iphy = &ihost->phys[index]; 920 - state = iphy->sm.current_state_id; 921 - 922 - if (!phy_get_non_dummy_port(iphy)) 923 - continue; 924 - 925 - /* The controller start operation is complete iff: 926 - * - all links have been given an opportunity to start 927 - * - have no indication of a connected device 928 - * - have an indication of a connected device and it has 929 - * finished the link training process. 930 - */ 931 - if ((iphy->is_in_link_training == false && state == SCI_PHY_INITIAL) || 932 - (iphy->is_in_link_training == false && state == SCI_PHY_STOPPED) || 933 - (iphy->is_in_link_training == true && is_phy_starting(iphy)) || 934 - (ihost->port_agent.phy_ready_mask != ihost->port_agent.phy_configured_mask)) { 935 - is_controller_start_complete = false; 936 - break; 937 - } 938 - } 939 - 940 - /* 941 - * The controller has successfully finished the start process. 942 - * Inform the SCI Core user and transition to the READY state. */ 943 - if (is_controller_start_complete == true) { 880 + if (is_controller_start_complete(ihost)) { 944 881 sci_controller_transition_to_ready(ihost, SCI_SUCCESS); 945 882 sci_del_timer(&ihost->phy_timer); 946 883 ihost->phy_startup_timer_pending = false; ··· 992 987 u16 index; 993 988 994 989 if (ihost->sm.current_state_id != SCIC_INITIALIZED) { 995 - dev_warn(&ihost->pdev->dev, 996 - "SCIC Controller start operation requested in " 997 - "invalid state\n"); 990 + dev_warn(&ihost->pdev->dev, "%s invalid state: %d\n", 991 + __func__, ihost->sm.current_state_id); 998 992 return SCI_FAILURE_INVALID_STATE; 999 993 } 1000 994 ··· 1057 1053 spin_unlock_irq(&ihost->scic_lock); 1058 1054 } 1059 1055 1060 - static void isci_host_stop_complete(struct isci_host *ihost, enum sci_status completion_status) 1056 + static void isci_host_stop_complete(struct isci_host *ihost) 1061 1057 { 1062 - isci_host_change_state(ihost, isci_stopped); 1063 1058 sci_controller_disable_interrupts(ihost); 1064 1059 clear_bit(IHOST_STOP_PENDING, &ihost->flags); 1065 1060 wake_up(&ihost->eventq); ··· 1077 1074 writel(0, &ihost->smu_registers->interrupt_mask); 1078 1075 } 1079 1076 1077 + void ireq_done(struct isci_host *ihost, struct isci_request *ireq, struct sas_task *task) 1078 + { 1079 + task->lldd_task = NULL; 1080 + if (!test_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags) && 1081 + !(task->task_state_flags & SAS_TASK_STATE_ABORTED)) { 1082 + if (test_bit(IREQ_COMPLETE_IN_TARGET, &ireq->flags)) { 1083 + /* Normal notification (task_done) */ 1084 + dev_dbg(&ihost->pdev->dev, 1085 + "%s: Normal - ireq/task = %p/%p\n", 1086 + __func__, ireq, task); 1087 + 1088 + task->task_done(task); 1089 + } else { 1090 + dev_dbg(&ihost->pdev->dev, 1091 + "%s: Error - ireq/task = %p/%p\n", 1092 + __func__, ireq, task); 1093 + 1094 + sas_task_abort(task); 1095 + } 1096 + } 1097 + if (test_and_clear_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags)) 1098 + wake_up_all(&ihost->eventq); 1099 + 1100 + if (!test_bit(IREQ_NO_AUTO_FREE_TAG, &ireq->flags)) 1101 + isci_free_tag(ihost, ireq->io_tag); 1102 + } 1080 1103 /** 1081 1104 * isci_host_completion_routine() - This function is the delayed service 1082 1105 * routine that calls the sci core library's completion handler. It's ··· 1111 1082 * @data: This parameter specifies the ISCI host object 1112 1083 * 1113 1084 */ 1114 - static void isci_host_completion_routine(unsigned long data) 1085 + void isci_host_completion_routine(unsigned long data) 1115 1086 { 1116 1087 struct isci_host *ihost = (struct isci_host *)data; 1117 - struct list_head completed_request_list; 1118 - struct list_head errored_request_list; 1119 - struct list_head *current_position; 1120 - struct list_head *next_position; 1121 - struct isci_request *request; 1122 - struct isci_request *next_request; 1123 - struct sas_task *task; 1124 1088 u16 active; 1125 1089 1126 - INIT_LIST_HEAD(&completed_request_list); 1127 - INIT_LIST_HEAD(&errored_request_list); 1128 - 1129 1090 spin_lock_irq(&ihost->scic_lock); 1130 - 1131 1091 sci_controller_completion_handler(ihost); 1132 - 1133 - /* Take the lists of completed I/Os from the host. */ 1134 - 1135 - list_splice_init(&ihost->requests_to_complete, 1136 - &completed_request_list); 1137 - 1138 - /* Take the list of errored I/Os from the host. */ 1139 - list_splice_init(&ihost->requests_to_errorback, 1140 - &errored_request_list); 1141 - 1142 1092 spin_unlock_irq(&ihost->scic_lock); 1143 - 1144 - /* Process any completions in the lists. */ 1145 - list_for_each_safe(current_position, next_position, 1146 - &completed_request_list) { 1147 - 1148 - request = list_entry(current_position, struct isci_request, 1149 - completed_node); 1150 - task = isci_request_access_task(request); 1151 - 1152 - /* Normal notification (task_done) */ 1153 - dev_dbg(&ihost->pdev->dev, 1154 - "%s: Normal - request/task = %p/%p\n", 1155 - __func__, 1156 - request, 1157 - task); 1158 - 1159 - /* Return the task to libsas */ 1160 - if (task != NULL) { 1161 - 1162 - task->lldd_task = NULL; 1163 - if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) { 1164 - 1165 - /* If the task is already in the abort path, 1166 - * the task_done callback cannot be called. 1167 - */ 1168 - task->task_done(task); 1169 - } 1170 - } 1171 - 1172 - spin_lock_irq(&ihost->scic_lock); 1173 - isci_free_tag(ihost, request->io_tag); 1174 - spin_unlock_irq(&ihost->scic_lock); 1175 - } 1176 - list_for_each_entry_safe(request, next_request, &errored_request_list, 1177 - completed_node) { 1178 - 1179 - task = isci_request_access_task(request); 1180 - 1181 - /* Use sas_task_abort */ 1182 - dev_warn(&ihost->pdev->dev, 1183 - "%s: Error - request/task = %p/%p\n", 1184 - __func__, 1185 - request, 1186 - task); 1187 - 1188 - if (task != NULL) { 1189 - 1190 - /* Put the task into the abort path if it's not there 1191 - * already. 1192 - */ 1193 - if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) 1194 - sas_task_abort(task); 1195 - 1196 - } else { 1197 - /* This is a case where the request has completed with a 1198 - * status such that it needed further target servicing, 1199 - * but the sas_task reference has already been removed 1200 - * from the request. Since it was errored, it was not 1201 - * being aborted, so there is nothing to do except free 1202 - * it. 1203 - */ 1204 - 1205 - spin_lock_irq(&ihost->scic_lock); 1206 - /* Remove the request from the remote device's list 1207 - * of pending requests. 1208 - */ 1209 - list_del_init(&request->dev_node); 1210 - isci_free_tag(ihost, request->io_tag); 1211 - spin_unlock_irq(&ihost->scic_lock); 1212 - } 1213 - } 1214 1093 1215 1094 /* the coalesence timeout doubles at each encoding step, so 1216 1095 * update it based on the ilog2 value of the outstanding requests ··· 1150 1213 static enum sci_status sci_controller_stop(struct isci_host *ihost, u32 timeout) 1151 1214 { 1152 1215 if (ihost->sm.current_state_id != SCIC_READY) { 1153 - dev_warn(&ihost->pdev->dev, 1154 - "SCIC Controller stop operation requested in " 1155 - "invalid state\n"); 1216 + dev_warn(&ihost->pdev->dev, "%s invalid state: %d\n", 1217 + __func__, ihost->sm.current_state_id); 1156 1218 return SCI_FAILURE_INVALID_STATE; 1157 1219 } 1158 1220 ··· 1177 1241 switch (ihost->sm.current_state_id) { 1178 1242 case SCIC_RESET: 1179 1243 case SCIC_READY: 1180 - case SCIC_STOPPED: 1244 + case SCIC_STOPPING: 1181 1245 case SCIC_FAILED: 1182 1246 /* 1183 1247 * The reset operation is not a graceful cleanup, just ··· 1186 1250 sci_change_state(&ihost->sm, SCIC_RESETTING); 1187 1251 return SCI_SUCCESS; 1188 1252 default: 1189 - dev_warn(&ihost->pdev->dev, 1190 - "SCIC Controller reset operation requested in " 1191 - "invalid state\n"); 1253 + dev_warn(&ihost->pdev->dev, "%s invalid state: %d\n", 1254 + __func__, ihost->sm.current_state_id); 1192 1255 return SCI_FAILURE_INVALID_STATE; 1193 1256 } 1194 1257 } 1195 1258 1259 + static enum sci_status sci_controller_stop_phys(struct isci_host *ihost) 1260 + { 1261 + u32 index; 1262 + enum sci_status status; 1263 + enum sci_status phy_status; 1264 + 1265 + status = SCI_SUCCESS; 1266 + 1267 + for (index = 0; index < SCI_MAX_PHYS; index++) { 1268 + phy_status = sci_phy_stop(&ihost->phys[index]); 1269 + 1270 + if (phy_status != SCI_SUCCESS && 1271 + phy_status != SCI_FAILURE_INVALID_STATE) { 1272 + status = SCI_FAILURE; 1273 + 1274 + dev_warn(&ihost->pdev->dev, 1275 + "%s: Controller stop operation failed to stop " 1276 + "phy %d because of status %d.\n", 1277 + __func__, 1278 + ihost->phys[index].phy_index, phy_status); 1279 + } 1280 + } 1281 + 1282 + return status; 1283 + } 1284 + 1285 + 1286 + /** 1287 + * isci_host_deinit - shutdown frame reception and dma 1288 + * @ihost: host to take down 1289 + * 1290 + * This is called in either the driver shutdown or the suspend path. In 1291 + * the shutdown case libsas went through port teardown and normal device 1292 + * removal (i.e. physical links stayed up to service scsi_device removal 1293 + * commands). In the suspend case we disable the hardware without 1294 + * notifying libsas of the link down events since we want libsas to 1295 + * remember the domain across the suspend/resume cycle 1296 + */ 1196 1297 void isci_host_deinit(struct isci_host *ihost) 1197 1298 { 1198 1299 int i; ··· 1237 1264 /* disable output data selects */ 1238 1265 for (i = 0; i < isci_gpio_count(ihost); i++) 1239 1266 writel(SGPIO_HW_CONTROL, &ihost->scu_registers->peg0.sgpio.output_data_select[i]); 1240 - 1241 - isci_host_change_state(ihost, isci_stopping); 1242 - for (i = 0; i < SCI_MAX_PORTS; i++) { 1243 - struct isci_port *iport = &ihost->ports[i]; 1244 - struct isci_remote_device *idev, *d; 1245 - 1246 - list_for_each_entry_safe(idev, d, &iport->remote_dev_list, node) { 1247 - if (test_bit(IDEV_ALLOCATED, &idev->flags)) 1248 - isci_remote_device_stop(ihost, idev); 1249 - } 1250 - } 1251 1267 1252 1268 set_bit(IHOST_STOP_PENDING, &ihost->flags); 1253 1269 ··· 1246 1284 1247 1285 wait_for_stop(ihost); 1248 1286 1287 + /* phy stop is after controller stop to allow port and device to 1288 + * go idle before shutting down the phys, but the expectation is 1289 + * that i/o has been shut off well before we reach this 1290 + * function. 1291 + */ 1292 + sci_controller_stop_phys(ihost); 1293 + 1249 1294 /* disable sgpio: where the above wait should give time for the 1250 1295 * enclosure to sample the gpios going inactive 1251 1296 */ 1252 1297 writel(0, &ihost->scu_registers->peg0.sgpio.interface_control); 1253 1298 1299 + spin_lock_irq(&ihost->scic_lock); 1254 1300 sci_controller_reset(ihost); 1301 + spin_unlock_irq(&ihost->scic_lock); 1255 1302 1256 1303 /* Cancel any/all outstanding port timers */ 1257 1304 for (i = 0; i < ihost->logical_port_entries; i++) { ··· 1297 1326 int id = isci_host->id; 1298 1327 1299 1328 return pcim_iomap_table(pdev)[SCI_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id; 1300 - } 1301 - 1302 - static void isci_user_parameters_get(struct sci_user_parameters *u) 1303 - { 1304 - int i; 1305 - 1306 - for (i = 0; i < SCI_MAX_PHYS; i++) { 1307 - struct sci_phy_user_params *u_phy = &u->phys[i]; 1308 - 1309 - u_phy->max_speed_generation = phy_gen; 1310 - 1311 - /* we are not exporting these for now */ 1312 - u_phy->align_insertion_frequency = 0x7f; 1313 - u_phy->in_connection_align_insertion_frequency = 0xff; 1314 - u_phy->notify_enable_spin_up_insertion_frequency = 0x33; 1315 - } 1316 - 1317 - u->stp_inactivity_timeout = stp_inactive_to; 1318 - u->ssp_inactivity_timeout = ssp_inactive_to; 1319 - u->stp_max_occupancy_timeout = stp_max_occ_to; 1320 - u->ssp_max_occupancy_timeout = ssp_max_occ_to; 1321 - u->no_outbound_task_timeout = no_outbound_task_to; 1322 - u->max_concurr_spinup = max_concurr_spinup; 1323 1329 } 1324 1330 1325 1331 static void sci_controller_initial_state_enter(struct sci_base_state_machine *sm) ··· 1458 1510 sci_controller_set_interrupt_coalescence(ihost, 0, 0); 1459 1511 } 1460 1512 1461 - static enum sci_status sci_controller_stop_phys(struct isci_host *ihost) 1462 - { 1463 - u32 index; 1464 - enum sci_status status; 1465 - enum sci_status phy_status; 1466 - 1467 - status = SCI_SUCCESS; 1468 - 1469 - for (index = 0; index < SCI_MAX_PHYS; index++) { 1470 - phy_status = sci_phy_stop(&ihost->phys[index]); 1471 - 1472 - if (phy_status != SCI_SUCCESS && 1473 - phy_status != SCI_FAILURE_INVALID_STATE) { 1474 - status = SCI_FAILURE; 1475 - 1476 - dev_warn(&ihost->pdev->dev, 1477 - "%s: Controller stop operation failed to stop " 1478 - "phy %d because of status %d.\n", 1479 - __func__, 1480 - ihost->phys[index].phy_index, phy_status); 1481 - } 1482 - } 1483 - 1484 - return status; 1485 - } 1486 - 1487 1513 static enum sci_status sci_controller_stop_ports(struct isci_host *ihost) 1488 1514 { 1489 1515 u32 index; ··· 1517 1595 { 1518 1596 struct isci_host *ihost = container_of(sm, typeof(*ihost), sm); 1519 1597 1520 - /* Stop all of the components for this controller */ 1521 - sci_controller_stop_phys(ihost); 1522 - sci_controller_stop_ports(ihost); 1523 1598 sci_controller_stop_devices(ihost); 1599 + sci_controller_stop_ports(ihost); 1600 + 1601 + if (!sci_controller_has_remote_devices_stopping(ihost)) 1602 + isci_host_stop_complete(ihost); 1524 1603 } 1525 1604 1526 1605 static void sci_controller_stopping_state_exit(struct sci_base_state_machine *sm) ··· 1547 1624 1548 1625 /* The write to the UFQGP clears the UFQPR */ 1549 1626 writel(0, &ihost->scu_registers->sdma.unsolicited_frame_get_pointer); 1627 + 1628 + /* clear all interrupts */ 1629 + writel(~SMU_INTERRUPT_STATUS_RESERVED_MASK, &ihost->smu_registers->interrupt_status); 1550 1630 } 1551 1631 1552 1632 static void sci_controller_resetting_state_enter(struct sci_base_state_machine *sm) ··· 1581 1655 .enter_state = sci_controller_stopping_state_enter, 1582 1656 .exit_state = sci_controller_stopping_state_exit, 1583 1657 }, 1584 - [SCIC_STOPPED] = {}, 1585 1658 [SCIC_FAILED] = {} 1586 1659 }; 1587 - 1588 - static void sci_controller_set_default_config_parameters(struct isci_host *ihost) 1589 - { 1590 - /* these defaults are overridden by the platform / firmware */ 1591 - u16 index; 1592 - 1593 - /* Default to APC mode. */ 1594 - ihost->oem_parameters.controller.mode_type = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE; 1595 - 1596 - /* Default to APC mode. */ 1597 - ihost->oem_parameters.controller.max_concurr_spin_up = 1; 1598 - 1599 - /* Default to no SSC operation. */ 1600 - ihost->oem_parameters.controller.do_enable_ssc = false; 1601 - 1602 - /* Default to short cables on all phys. */ 1603 - ihost->oem_parameters.controller.cable_selection_mask = 0; 1604 - 1605 - /* Initialize all of the port parameter information to narrow ports. */ 1606 - for (index = 0; index < SCI_MAX_PORTS; index++) { 1607 - ihost->oem_parameters.ports[index].phy_mask = 0; 1608 - } 1609 - 1610 - /* Initialize all of the phy parameter information. */ 1611 - for (index = 0; index < SCI_MAX_PHYS; index++) { 1612 - /* Default to 3G (i.e. Gen 2). */ 1613 - ihost->user_parameters.phys[index].max_speed_generation = 1614 - SCIC_SDS_PARM_GEN2_SPEED; 1615 - 1616 - /* the frequencies cannot be 0 */ 1617 - ihost->user_parameters.phys[index].align_insertion_frequency = 0x7f; 1618 - ihost->user_parameters.phys[index].in_connection_align_insertion_frequency = 0xff; 1619 - ihost->user_parameters.phys[index].notify_enable_spin_up_insertion_frequency = 0x33; 1620 - 1621 - /* 1622 - * Previous Vitesse based expanders had a arbitration issue that 1623 - * is worked around by having the upper 32-bits of SAS address 1624 - * with a value greater then the Vitesse company identifier. 1625 - * Hence, usage of 0x5FCFFFFF. */ 1626 - ihost->oem_parameters.phys[index].sas_address.low = 0x1 + ihost->id; 1627 - ihost->oem_parameters.phys[index].sas_address.high = 0x5FCFFFFF; 1628 - } 1629 - 1630 - ihost->user_parameters.stp_inactivity_timeout = 5; 1631 - ihost->user_parameters.ssp_inactivity_timeout = 5; 1632 - ihost->user_parameters.stp_max_occupancy_timeout = 5; 1633 - ihost->user_parameters.ssp_max_occupancy_timeout = 20; 1634 - ihost->user_parameters.no_outbound_task_timeout = 2; 1635 - } 1636 1660 1637 1661 static void controller_timeout(unsigned long data) 1638 1662 { ··· 1600 1724 sci_controller_transition_to_ready(ihost, SCI_FAILURE_TIMEOUT); 1601 1725 else if (sm->current_state_id == SCIC_STOPPING) { 1602 1726 sci_change_state(sm, SCIC_FAILED); 1603 - isci_host_stop_complete(ihost, SCI_FAILURE_TIMEOUT); 1727 + isci_host_stop_complete(ihost); 1604 1728 } else /* / @todo Now what do we want to do in this case? */ 1605 1729 dev_err(&ihost->pdev->dev, 1606 1730 "%s: Controller timer fired when controller was not " ··· 1639 1763 ihost->invalid_phy_mask = 0; 1640 1764 1641 1765 sci_init_timer(&ihost->timer, controller_timeout); 1642 - 1643 - /* Initialize the User and OEM parameters to default values. */ 1644 - sci_controller_set_default_config_parameters(ihost); 1645 1766 1646 1767 return sci_controller_reset(ihost); 1647 1768 } ··· 1719 1846 return 0; 1720 1847 } 1721 1848 1722 - static enum sci_status sci_oem_parameters_set(struct isci_host *ihost) 1723 - { 1724 - u32 state = ihost->sm.current_state_id; 1725 - struct isci_pci_info *pci_info = to_pci_info(ihost->pdev); 1726 - 1727 - if (state == SCIC_RESET || 1728 - state == SCIC_INITIALIZING || 1729 - state == SCIC_INITIALIZED) { 1730 - u8 oem_version = pci_info->orom ? pci_info->orom->hdr.version : 1731 - ISCI_ROM_VER_1_0; 1732 - 1733 - if (sci_oem_parameters_validate(&ihost->oem_parameters, 1734 - oem_version)) 1735 - return SCI_FAILURE_INVALID_PARAMETER_VALUE; 1736 - 1737 - return SCI_SUCCESS; 1738 - } 1739 - 1740 - return SCI_FAILURE_INVALID_STATE; 1741 - } 1742 - 1743 1849 static u8 max_spin_up(struct isci_host *ihost) 1744 1850 { 1745 1851 if (ihost->user_parameters.max_concurr_spinup) ··· 1766 1914 ihost->power_control.phys_granted_power++; 1767 1915 sci_phy_consume_power_handler(iphy); 1768 1916 1769 - if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) { 1917 + if (iphy->protocol == SAS_PROTOCOL_SSP) { 1770 1918 u8 j; 1771 1919 1772 1920 for (j = 0; j < SCI_MAX_PHYS; j++) { ··· 1840 1988 sizeof(current_phy->frame_rcvd.iaf.sas_addr)); 1841 1989 1842 1990 if (current_phy->sm.current_state_id == SCI_PHY_READY && 1843 - current_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS && 1991 + current_phy->protocol == SAS_PROTOCOL_SSP && 1844 1992 other == 0) { 1845 1993 sci_phy_consume_power_handler(iphy); 1846 1994 break; ··· 2131 2279 unsigned long i, state, val; 2132 2280 2133 2281 if (ihost->sm.current_state_id != SCIC_RESET) { 2134 - dev_warn(&ihost->pdev->dev, 2135 - "SCIC Controller initialize operation requested " 2136 - "in invalid state\n"); 2282 + dev_warn(&ihost->pdev->dev, "%s invalid state: %d\n", 2283 + __func__, ihost->sm.current_state_id); 2137 2284 return SCI_FAILURE_INVALID_STATE; 2138 2285 } 2139 2286 ··· 2235 2384 return result; 2236 2385 } 2237 2386 2238 - static enum sci_status sci_user_parameters_set(struct isci_host *ihost, 2239 - struct sci_user_parameters *sci_parms) 2387 + static int sci_controller_dma_alloc(struct isci_host *ihost) 2240 2388 { 2241 - u32 state = ihost->sm.current_state_id; 2389 + struct device *dev = &ihost->pdev->dev; 2390 + size_t size; 2391 + int i; 2242 2392 2243 - if (state == SCIC_RESET || 2244 - state == SCIC_INITIALIZING || 2245 - state == SCIC_INITIALIZED) { 2246 - u16 index; 2393 + /* detect re-initialization */ 2394 + if (ihost->completion_queue) 2395 + return 0; 2247 2396 2248 - /* 2249 - * Validate the user parameters. If they are not legal, then 2250 - * return a failure. 2251 - */ 2252 - for (index = 0; index < SCI_MAX_PHYS; index++) { 2253 - struct sci_phy_user_params *user_phy; 2397 + size = SCU_MAX_COMPLETION_QUEUE_ENTRIES * sizeof(u32); 2398 + ihost->completion_queue = dmam_alloc_coherent(dev, size, &ihost->cq_dma, 2399 + GFP_KERNEL); 2400 + if (!ihost->completion_queue) 2401 + return -ENOMEM; 2254 2402 2255 - user_phy = &sci_parms->phys[index]; 2403 + size = ihost->remote_node_entries * sizeof(union scu_remote_node_context); 2404 + ihost->remote_node_context_table = dmam_alloc_coherent(dev, size, &ihost->rnc_dma, 2405 + GFP_KERNEL); 2256 2406 2257 - if (!((user_phy->max_speed_generation <= 2258 - SCIC_SDS_PARM_MAX_SPEED) && 2259 - (user_phy->max_speed_generation > 2260 - SCIC_SDS_PARM_NO_SPEED))) 2261 - return SCI_FAILURE_INVALID_PARAMETER_VALUE; 2407 + if (!ihost->remote_node_context_table) 2408 + return -ENOMEM; 2262 2409 2263 - if (user_phy->in_connection_align_insertion_frequency < 2264 - 3) 2265 - return SCI_FAILURE_INVALID_PARAMETER_VALUE; 2410 + size = ihost->task_context_entries * sizeof(struct scu_task_context), 2411 + ihost->task_context_table = dmam_alloc_coherent(dev, size, &ihost->tc_dma, 2412 + GFP_KERNEL); 2413 + if (!ihost->task_context_table) 2414 + return -ENOMEM; 2266 2415 2267 - if ((user_phy->in_connection_align_insertion_frequency < 2268 - 3) || 2269 - (user_phy->align_insertion_frequency == 0) || 2270 - (user_phy-> 2271 - notify_enable_spin_up_insertion_frequency == 2272 - 0)) 2273 - return SCI_FAILURE_INVALID_PARAMETER_VALUE; 2274 - } 2416 + size = SCI_UFI_TOTAL_SIZE; 2417 + ihost->ufi_buf = dmam_alloc_coherent(dev, size, &ihost->ufi_dma, GFP_KERNEL); 2418 + if (!ihost->ufi_buf) 2419 + return -ENOMEM; 2275 2420 2276 - if ((sci_parms->stp_inactivity_timeout == 0) || 2277 - (sci_parms->ssp_inactivity_timeout == 0) || 2278 - (sci_parms->stp_max_occupancy_timeout == 0) || 2279 - (sci_parms->ssp_max_occupancy_timeout == 0) || 2280 - (sci_parms->no_outbound_task_timeout == 0)) 2281 - return SCI_FAILURE_INVALID_PARAMETER_VALUE; 2421 + for (i = 0; i < SCI_MAX_IO_REQUESTS; i++) { 2422 + struct isci_request *ireq; 2423 + dma_addr_t dma; 2282 2424 2283 - memcpy(&ihost->user_parameters, sci_parms, sizeof(*sci_parms)); 2425 + ireq = dmam_alloc_coherent(dev, sizeof(*ireq), &dma, GFP_KERNEL); 2426 + if (!ireq) 2427 + return -ENOMEM; 2284 2428 2285 - return SCI_SUCCESS; 2429 + ireq->tc = &ihost->task_context_table[i]; 2430 + ireq->owning_controller = ihost; 2431 + ireq->request_daddr = dma; 2432 + ireq->isci_host = ihost; 2433 + ihost->reqs[i] = ireq; 2286 2434 } 2287 2435 2288 - return SCI_FAILURE_INVALID_STATE; 2436 + return 0; 2289 2437 } 2290 2438 2291 2439 static int sci_controller_mem_init(struct isci_host *ihost) 2292 2440 { 2293 - struct device *dev = &ihost->pdev->dev; 2294 - dma_addr_t dma; 2295 - size_t size; 2296 - int err; 2441 + int err = sci_controller_dma_alloc(ihost); 2297 2442 2298 - size = SCU_MAX_COMPLETION_QUEUE_ENTRIES * sizeof(u32); 2299 - ihost->completion_queue = dmam_alloc_coherent(dev, size, &dma, GFP_KERNEL); 2300 - if (!ihost->completion_queue) 2301 - return -ENOMEM; 2302 - 2303 - writel(lower_32_bits(dma), &ihost->smu_registers->completion_queue_lower); 2304 - writel(upper_32_bits(dma), &ihost->smu_registers->completion_queue_upper); 2305 - 2306 - size = ihost->remote_node_entries * sizeof(union scu_remote_node_context); 2307 - ihost->remote_node_context_table = dmam_alloc_coherent(dev, size, &dma, 2308 - GFP_KERNEL); 2309 - if (!ihost->remote_node_context_table) 2310 - return -ENOMEM; 2311 - 2312 - writel(lower_32_bits(dma), &ihost->smu_registers->remote_node_context_lower); 2313 - writel(upper_32_bits(dma), &ihost->smu_registers->remote_node_context_upper); 2314 - 2315 - size = ihost->task_context_entries * sizeof(struct scu_task_context), 2316 - ihost->task_context_table = dmam_alloc_coherent(dev, size, &dma, GFP_KERNEL); 2317 - if (!ihost->task_context_table) 2318 - return -ENOMEM; 2319 - 2320 - ihost->task_context_dma = dma; 2321 - writel(lower_32_bits(dma), &ihost->smu_registers->host_task_table_lower); 2322 - writel(upper_32_bits(dma), &ihost->smu_registers->host_task_table_upper); 2323 - 2324 - err = sci_unsolicited_frame_control_construct(ihost); 2325 2443 if (err) 2326 2444 return err; 2445 + 2446 + writel(lower_32_bits(ihost->cq_dma), &ihost->smu_registers->completion_queue_lower); 2447 + writel(upper_32_bits(ihost->cq_dma), &ihost->smu_registers->completion_queue_upper); 2448 + 2449 + writel(lower_32_bits(ihost->rnc_dma), &ihost->smu_registers->remote_node_context_lower); 2450 + writel(upper_32_bits(ihost->rnc_dma), &ihost->smu_registers->remote_node_context_upper); 2451 + 2452 + writel(lower_32_bits(ihost->tc_dma), &ihost->smu_registers->host_task_table_lower); 2453 + writel(upper_32_bits(ihost->tc_dma), &ihost->smu_registers->host_task_table_upper); 2454 + 2455 + sci_unsolicited_frame_control_construct(ihost); 2327 2456 2328 2457 /* 2329 2458 * Inform the silicon as to the location of the UF headers and ··· 2322 2491 return 0; 2323 2492 } 2324 2493 2494 + /** 2495 + * isci_host_init - (re-)initialize hardware and internal (private) state 2496 + * @ihost: host to init 2497 + * 2498 + * Any public facing objects (like asd_sas_port, and asd_sas_phys), or 2499 + * one-time initialization objects like locks and waitqueues, are 2500 + * not touched (they are initialized in isci_host_alloc) 2501 + */ 2325 2502 int isci_host_init(struct isci_host *ihost) 2326 2503 { 2327 - int err = 0, i; 2504 + int i, err; 2328 2505 enum sci_status status; 2329 - struct sci_user_parameters sci_user_params; 2330 - struct isci_pci_info *pci_info = to_pci_info(ihost->pdev); 2331 2506 2332 - spin_lock_init(&ihost->state_lock); 2333 - spin_lock_init(&ihost->scic_lock); 2334 - init_waitqueue_head(&ihost->eventq); 2335 - 2336 - isci_host_change_state(ihost, isci_starting); 2337 - 2338 - status = sci_controller_construct(ihost, scu_base(ihost), 2339 - smu_base(ihost)); 2340 - 2507 + spin_lock_irq(&ihost->scic_lock); 2508 + status = sci_controller_construct(ihost, scu_base(ihost), smu_base(ihost)); 2509 + spin_unlock_irq(&ihost->scic_lock); 2341 2510 if (status != SCI_SUCCESS) { 2342 2511 dev_err(&ihost->pdev->dev, 2343 2512 "%s: sci_controller_construct failed - status = %x\n", ··· 2345 2514 status); 2346 2515 return -ENODEV; 2347 2516 } 2348 - 2349 - ihost->sas_ha.dev = &ihost->pdev->dev; 2350 - ihost->sas_ha.lldd_ha = ihost; 2351 - 2352 - /* 2353 - * grab initial values stored in the controller object for OEM and USER 2354 - * parameters 2355 - */ 2356 - isci_user_parameters_get(&sci_user_params); 2357 - status = sci_user_parameters_set(ihost, &sci_user_params); 2358 - if (status != SCI_SUCCESS) { 2359 - dev_warn(&ihost->pdev->dev, 2360 - "%s: sci_user_parameters_set failed\n", 2361 - __func__); 2362 - return -ENODEV; 2363 - } 2364 - 2365 - /* grab any OEM parameters specified in orom */ 2366 - if (pci_info->orom) { 2367 - status = isci_parse_oem_parameters(&ihost->oem_parameters, 2368 - pci_info->orom, 2369 - ihost->id); 2370 - if (status != SCI_SUCCESS) { 2371 - dev_warn(&ihost->pdev->dev, 2372 - "parsing firmware oem parameters failed\n"); 2373 - return -EINVAL; 2374 - } 2375 - } 2376 - 2377 - status = sci_oem_parameters_set(ihost); 2378 - if (status != SCI_SUCCESS) { 2379 - dev_warn(&ihost->pdev->dev, 2380 - "%s: sci_oem_parameters_set failed\n", 2381 - __func__); 2382 - return -ENODEV; 2383 - } 2384 - 2385 - tasklet_init(&ihost->completion_tasklet, 2386 - isci_host_completion_routine, (unsigned long)ihost); 2387 - 2388 - INIT_LIST_HEAD(&ihost->requests_to_complete); 2389 - INIT_LIST_HEAD(&ihost->requests_to_errorback); 2390 2517 2391 2518 spin_lock_irq(&ihost->scic_lock); 2392 2519 status = sci_controller_initialize(ihost); ··· 2361 2572 if (err) 2362 2573 return err; 2363 2574 2364 - for (i = 0; i < SCI_MAX_PORTS; i++) 2365 - isci_port_init(&ihost->ports[i], ihost, i); 2366 - 2367 - for (i = 0; i < SCI_MAX_PHYS; i++) 2368 - isci_phy_init(&ihost->phys[i], ihost, i); 2369 - 2370 2575 /* enable sgpio */ 2371 2576 writel(1, &ihost->scu_registers->peg0.sgpio.interface_control); 2372 2577 for (i = 0; i < isci_gpio_count(ihost); i++) 2373 2578 writel(SGPIO_HW_CONTROL, &ihost->scu_registers->peg0.sgpio.output_data_select[i]); 2374 2579 writel(0, &ihost->scu_registers->peg0.sgpio.vendor_specific_code); 2375 - 2376 - for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) { 2377 - struct isci_remote_device *idev = &ihost->devices[i]; 2378 - 2379 - INIT_LIST_HEAD(&idev->reqs_in_process); 2380 - INIT_LIST_HEAD(&idev->node); 2381 - } 2382 - 2383 - for (i = 0; i < SCI_MAX_IO_REQUESTS; i++) { 2384 - struct isci_request *ireq; 2385 - dma_addr_t dma; 2386 - 2387 - ireq = dmam_alloc_coherent(&ihost->pdev->dev, 2388 - sizeof(struct isci_request), &dma, 2389 - GFP_KERNEL); 2390 - if (!ireq) 2391 - return -ENOMEM; 2392 - 2393 - ireq->tc = &ihost->task_context_table[i]; 2394 - ireq->owning_controller = ihost; 2395 - spin_lock_init(&ireq->state_lock); 2396 - ireq->request_daddr = dma; 2397 - ireq->isci_host = ihost; 2398 - ihost->reqs[i] = ireq; 2399 - } 2400 2580 2401 2581 return 0; 2402 2582 } ··· 2412 2654 } 2413 2655 } 2414 2656 2415 - static bool sci_controller_has_remote_devices_stopping(struct isci_host *ihost) 2657 + bool sci_controller_has_remote_devices_stopping(struct isci_host *ihost) 2416 2658 { 2417 2659 u32 index; 2418 2660 ··· 2438 2680 } 2439 2681 2440 2682 if (!sci_controller_has_remote_devices_stopping(ihost)) 2441 - sci_change_state(&ihost->sm, SCIC_STOPPED); 2683 + isci_host_stop_complete(ihost); 2442 2684 } 2443 2685 2444 2686 void sci_controller_post_request(struct isci_host *ihost, u32 request) ··· 2600 2842 enum sci_status status; 2601 2843 2602 2844 if (ihost->sm.current_state_id != SCIC_READY) { 2603 - dev_warn(&ihost->pdev->dev, "invalid state to start I/O"); 2845 + dev_warn(&ihost->pdev->dev, "%s invalid state: %d\n", 2846 + __func__, ihost->sm.current_state_id); 2604 2847 return SCI_FAILURE_INVALID_STATE; 2605 2848 } 2606 2849 ··· 2625 2866 enum sci_status status; 2626 2867 2627 2868 if (ihost->sm.current_state_id != SCIC_READY) { 2628 - dev_warn(&ihost->pdev->dev, 2629 - "invalid state to terminate request\n"); 2869 + dev_warn(&ihost->pdev->dev, "%s invalid state: %d\n", 2870 + __func__, ihost->sm.current_state_id); 2630 2871 return SCI_FAILURE_INVALID_STATE; 2631 2872 } 2632 - 2633 2873 status = sci_io_request_terminate(ireq); 2634 - if (status != SCI_SUCCESS) 2635 - return status; 2636 2874 2637 - /* 2638 - * Utilize the original post context command and or in the POST_TC_ABORT 2639 - * request sub-type. 2640 - */ 2641 - sci_controller_post_request(ihost, 2642 - ireq->post_context | SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT); 2643 - return SCI_SUCCESS; 2875 + dev_dbg(&ihost->pdev->dev, "%s: status=%d; ireq=%p; flags=%lx\n", 2876 + __func__, status, ireq, ireq->flags); 2877 + 2878 + if ((status == SCI_SUCCESS) && 2879 + !test_bit(IREQ_PENDING_ABORT, &ireq->flags) && 2880 + !test_and_set_bit(IREQ_TC_ABORT_POSTED, &ireq->flags)) { 2881 + /* Utilize the original post context command and or in the 2882 + * POST_TC_ABORT request sub-type. 2883 + */ 2884 + sci_controller_post_request( 2885 + ihost, ireq->post_context | 2886 + SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT); 2887 + } 2888 + return status; 2644 2889 } 2645 2890 2646 2891 /** ··· 2678 2915 clear_bit(IREQ_ACTIVE, &ireq->flags); 2679 2916 return SCI_SUCCESS; 2680 2917 default: 2681 - dev_warn(&ihost->pdev->dev, "invalid state to complete I/O"); 2918 + dev_warn(&ihost->pdev->dev, "%s invalid state: %d\n", 2919 + __func__, ihost->sm.current_state_id); 2682 2920 return SCI_FAILURE_INVALID_STATE; 2683 2921 } 2684 2922 ··· 2690 2926 struct isci_host *ihost = ireq->owning_controller; 2691 2927 2692 2928 if (ihost->sm.current_state_id != SCIC_READY) { 2693 - dev_warn(&ihost->pdev->dev, "invalid state to continue I/O"); 2929 + dev_warn(&ihost->pdev->dev, "%s invalid state: %d\n", 2930 + __func__, ihost->sm.current_state_id); 2694 2931 return SCI_FAILURE_INVALID_STATE; 2695 2932 } 2696 2933
+37 -87
drivers/scsi/isci/host.h
··· 55 55 #ifndef _SCI_HOST_H_ 56 56 #define _SCI_HOST_H_ 57 57 58 + #include <scsi/sas_ata.h> 58 59 #include "remote_device.h" 59 60 #include "phy.h" 60 61 #include "isci.h" ··· 109 108 typedef void (*port_config_fn)(struct isci_host *, 110 109 struct sci_port_configuration_agent *, 111 110 struct isci_port *, struct isci_phy *); 111 + bool is_port_config_apc(struct isci_host *ihost); 112 + bool is_controller_start_complete(struct isci_host *ihost); 112 113 113 114 struct sci_port_configuration_agent { 114 115 u16 phy_configured_mask; ··· 160 157 struct sci_power_control power_control; 161 158 u8 io_request_sequence[SCI_MAX_IO_REQUESTS]; 162 159 struct scu_task_context *task_context_table; 163 - dma_addr_t task_context_dma; 160 + dma_addr_t tc_dma; 164 161 union scu_remote_node_context *remote_node_context_table; 162 + dma_addr_t rnc_dma; 165 163 u32 *completion_queue; 164 + dma_addr_t cq_dma; 166 165 u32 completion_queue_get; 167 166 u32 logical_port_entries; 168 167 u32 remote_node_entries; 169 168 u32 task_context_entries; 169 + void *ufi_buf; 170 + dma_addr_t ufi_dma; 170 171 struct sci_unsolicited_frame_control uf_control; 171 172 172 173 /* phy startup */ ··· 197 190 struct asd_sas_port sas_ports[SCI_MAX_PORTS]; 198 191 struct sas_ha_struct sas_ha; 199 192 200 - spinlock_t state_lock; 201 193 struct pci_dev *pdev; 202 - enum isci_status status; 203 194 #define IHOST_START_PENDING 0 204 195 #define IHOST_STOP_PENDING 1 196 + #define IHOST_IRQ_ENABLED 2 205 197 unsigned long flags; 206 198 wait_queue_head_t eventq; 207 - struct Scsi_Host *shost; 208 199 struct tasklet_struct completion_tasklet; 209 - struct list_head requests_to_complete; 210 - struct list_head requests_to_errorback; 211 200 spinlock_t scic_lock; 212 201 struct isci_request *reqs[SCI_MAX_IO_REQUESTS]; 213 202 struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES]; ··· 277 274 SCIC_STOPPING, 278 275 279 276 /** 280 - * This state indicates that the controller has successfully been stopped. 281 - * In this state no new IO operations are permitted. 282 - * This state is entered from the STOPPING state. 283 - */ 284 - SCIC_STOPPED, 285 - 286 - /** 287 277 * This state indicates that the controller could not successfully be 288 278 * initialized. In this state no new IO operations are permitted. 289 279 * This state is entered from the INITIALIZING state. ··· 305 309 return pci_get_drvdata(pdev); 306 310 } 307 311 312 + static inline struct Scsi_Host *to_shost(struct isci_host *ihost) 313 + { 314 + return ihost->sas_ha.core.shost; 315 + } 316 + 308 317 #define for_each_isci_host(id, ihost, pdev) \ 309 318 for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \ 310 319 id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ 311 320 ihost = to_pci_info(pdev)->hosts[++id]) 312 - 313 - static inline enum isci_status isci_host_get_state(struct isci_host *isci_host) 314 - { 315 - return isci_host->status; 316 - } 317 - 318 - static inline void isci_host_change_state(struct isci_host *isci_host, 319 - enum isci_status status) 320 - { 321 - unsigned long flags; 322 - 323 - dev_dbg(&isci_host->pdev->dev, 324 - "%s: isci_host = %p, state = 0x%x", 325 - __func__, 326 - isci_host, 327 - status); 328 - spin_lock_irqsave(&isci_host->state_lock, flags); 329 - isci_host->status = status; 330 - spin_unlock_irqrestore(&isci_host->state_lock, flags); 331 - 332 - } 333 321 334 322 static inline void wait_for_start(struct isci_host *ihost) 335 323 { ··· 340 360 return dev->port->ha->lldd_ha; 341 361 } 342 362 363 + static inline struct isci_host *idev_to_ihost(struct isci_remote_device *idev) 364 + { 365 + return dev_to_ihost(idev->domain_dev); 366 + } 367 + 343 368 /* we always use protocol engine group zero */ 344 369 #define ISCI_PEG 0 345 370 ··· 363 378 { 364 379 struct domain_device *dev = idev->domain_dev; 365 380 366 - if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) && 367 - !idev->is_direct_attached) 381 + if (dev_is_sata(dev) && dev->parent) 368 382 return SCU_STP_REMOTE_NODE_COUNT; 369 383 return SCU_SSP_REMOTE_NODE_COUNT; 370 384 } ··· 459 475 struct isci_remote_device *idev, 460 476 u16 node_id); 461 477 462 - struct isci_request *sci_request_by_tag(struct isci_host *ihost, 463 - u16 io_tag); 464 - 465 - void sci_controller_power_control_queue_insert( 466 - struct isci_host *ihost, 467 - struct isci_phy *iphy); 468 - 469 - void sci_controller_power_control_queue_remove( 470 - struct isci_host *ihost, 471 - struct isci_phy *iphy); 472 - 473 - void sci_controller_link_up( 474 - struct isci_host *ihost, 475 - struct isci_port *iport, 476 - struct isci_phy *iphy); 477 - 478 - void sci_controller_link_down( 479 - struct isci_host *ihost, 480 - struct isci_port *iport, 481 - struct isci_phy *iphy); 482 - 483 - void sci_controller_remote_device_stopped( 484 - struct isci_host *ihost, 485 - struct isci_remote_device *idev); 486 - 487 - void sci_controller_copy_task_context( 488 - struct isci_host *ihost, 489 - struct isci_request *ireq); 490 - 491 - void sci_controller_register_setup(struct isci_host *ihost); 478 + struct isci_request *sci_request_by_tag(struct isci_host *ihost, u16 io_tag); 479 + void sci_controller_power_control_queue_insert(struct isci_host *ihost, 480 + struct isci_phy *iphy); 481 + void sci_controller_power_control_queue_remove(struct isci_host *ihost, 482 + struct isci_phy *iphy); 483 + void sci_controller_link_up(struct isci_host *ihost, struct isci_port *iport, 484 + struct isci_phy *iphy); 485 + void sci_controller_link_down(struct isci_host *ihost, struct isci_port *iport, 486 + struct isci_phy *iphy); 487 + void sci_controller_remote_device_stopped(struct isci_host *ihost, 488 + struct isci_remote_device *idev); 492 489 493 490 enum sci_status sci_controller_continue_io(struct isci_request *ireq); 494 491 int isci_host_scan_finished(struct Scsi_Host *, unsigned long); ··· 477 512 u16 isci_alloc_tag(struct isci_host *ihost); 478 513 enum sci_status isci_free_tag(struct isci_host *ihost, u16 io_tag); 479 514 void isci_tci_free(struct isci_host *ihost, u16 tci); 515 + void ireq_done(struct isci_host *ihost, struct isci_request *ireq, struct sas_task *task); 480 516 481 517 int isci_host_init(struct isci_host *); 482 - 483 - void isci_host_init_controller_names( 484 - struct isci_host *isci_host, 485 - unsigned int controller_idx); 486 - 487 - void isci_host_deinit( 488 - struct isci_host *); 489 - 490 - void isci_host_port_link_up( 491 - struct isci_host *, 492 - struct isci_port *, 493 - struct isci_phy *); 494 - int isci_host_dev_found(struct domain_device *); 495 - 496 - void isci_host_remote_device_start_complete( 497 - struct isci_host *, 498 - struct isci_remote_device *, 499 - enum sci_status); 500 - 501 - void sci_controller_disable_interrupts( 502 - struct isci_host *ihost); 518 + void isci_host_completion_routine(unsigned long data); 519 + void isci_host_deinit(struct isci_host *); 520 + void sci_controller_disable_interrupts(struct isci_host *ihost); 521 + bool sci_controller_has_remote_devices_stopping(struct isci_host *ihost); 522 + void sci_controller_transition_to_ready(struct isci_host *ihost, enum sci_status status); 503 523 504 524 enum sci_status sci_controller_start_io( 505 525 struct isci_host *ihost,
+186 -26
drivers/scsi/isci/init.c
··· 271 271 if (!isci_host) 272 272 return; 273 273 274 - shost = isci_host->shost; 275 - 276 274 sas_unregister_ha(&isci_host->sas_ha); 277 275 278 - sas_remove_host(isci_host->shost); 279 - scsi_remove_host(isci_host->shost); 280 - scsi_host_put(isci_host->shost); 276 + shost = to_shost(isci_host); 277 + sas_remove_host(shost); 278 + scsi_remove_host(shost); 279 + scsi_host_put(shost); 281 280 } 282 281 283 282 static int __devinit isci_pci_init(struct pci_dev *pdev) ··· 396 397 return err; 397 398 } 398 399 400 + static void isci_user_parameters_get(struct sci_user_parameters *u) 401 + { 402 + int i; 403 + 404 + for (i = 0; i < SCI_MAX_PHYS; i++) { 405 + struct sci_phy_user_params *u_phy = &u->phys[i]; 406 + 407 + u_phy->max_speed_generation = phy_gen; 408 + 409 + /* we are not exporting these for now */ 410 + u_phy->align_insertion_frequency = 0x7f; 411 + u_phy->in_connection_align_insertion_frequency = 0xff; 412 + u_phy->notify_enable_spin_up_insertion_frequency = 0x33; 413 + } 414 + 415 + u->stp_inactivity_timeout = stp_inactive_to; 416 + u->ssp_inactivity_timeout = ssp_inactive_to; 417 + u->stp_max_occupancy_timeout = stp_max_occ_to; 418 + u->ssp_max_occupancy_timeout = ssp_max_occ_to; 419 + u->no_outbound_task_timeout = no_outbound_task_to; 420 + u->max_concurr_spinup = max_concurr_spinup; 421 + } 422 + 423 + static enum sci_status sci_user_parameters_set(struct isci_host *ihost, 424 + struct sci_user_parameters *sci_parms) 425 + { 426 + u16 index; 427 + 428 + /* 429 + * Validate the user parameters. If they are not legal, then 430 + * return a failure. 431 + */ 432 + for (index = 0; index < SCI_MAX_PHYS; index++) { 433 + struct sci_phy_user_params *u; 434 + 435 + u = &sci_parms->phys[index]; 436 + 437 + if (!((u->max_speed_generation <= SCIC_SDS_PARM_MAX_SPEED) && 438 + (u->max_speed_generation > SCIC_SDS_PARM_NO_SPEED))) 439 + return SCI_FAILURE_INVALID_PARAMETER_VALUE; 440 + 441 + if (u->in_connection_align_insertion_frequency < 3) 442 + return SCI_FAILURE_INVALID_PARAMETER_VALUE; 443 + 444 + if ((u->in_connection_align_insertion_frequency < 3) || 445 + (u->align_insertion_frequency == 0) || 446 + (u->notify_enable_spin_up_insertion_frequency == 0)) 447 + return SCI_FAILURE_INVALID_PARAMETER_VALUE; 448 + } 449 + 450 + if ((sci_parms->stp_inactivity_timeout == 0) || 451 + (sci_parms->ssp_inactivity_timeout == 0) || 452 + (sci_parms->stp_max_occupancy_timeout == 0) || 453 + (sci_parms->ssp_max_occupancy_timeout == 0) || 454 + (sci_parms->no_outbound_task_timeout == 0)) 455 + return SCI_FAILURE_INVALID_PARAMETER_VALUE; 456 + 457 + memcpy(&ihost->user_parameters, sci_parms, sizeof(*sci_parms)); 458 + 459 + return SCI_SUCCESS; 460 + } 461 + 462 + static void sci_oem_defaults(struct isci_host *ihost) 463 + { 464 + /* these defaults are overridden by the platform / firmware */ 465 + struct sci_user_parameters *user = &ihost->user_parameters; 466 + struct sci_oem_params *oem = &ihost->oem_parameters; 467 + int i; 468 + 469 + /* Default to APC mode. */ 470 + oem->controller.mode_type = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE; 471 + 472 + /* Default to APC mode. */ 473 + oem->controller.max_concurr_spin_up = 1; 474 + 475 + /* Default to no SSC operation. */ 476 + oem->controller.do_enable_ssc = false; 477 + 478 + /* Default to short cables on all phys. */ 479 + oem->controller.cable_selection_mask = 0; 480 + 481 + /* Initialize all of the port parameter information to narrow ports. */ 482 + for (i = 0; i < SCI_MAX_PORTS; i++) 483 + oem->ports[i].phy_mask = 0; 484 + 485 + /* Initialize all of the phy parameter information. */ 486 + for (i = 0; i < SCI_MAX_PHYS; i++) { 487 + /* Default to 3G (i.e. Gen 2). */ 488 + user->phys[i].max_speed_generation = SCIC_SDS_PARM_GEN2_SPEED; 489 + 490 + /* the frequencies cannot be 0 */ 491 + user->phys[i].align_insertion_frequency = 0x7f; 492 + user->phys[i].in_connection_align_insertion_frequency = 0xff; 493 + user->phys[i].notify_enable_spin_up_insertion_frequency = 0x33; 494 + 495 + /* Previous Vitesse based expanders had a arbitration issue that 496 + * is worked around by having the upper 32-bits of SAS address 497 + * with a value greater then the Vitesse company identifier. 498 + * Hence, usage of 0x5FCFFFFF. 499 + */ 500 + oem->phys[i].sas_address.low = 0x1 + ihost->id; 501 + oem->phys[i].sas_address.high = 0x5FCFFFFF; 502 + } 503 + 504 + user->stp_inactivity_timeout = 5; 505 + user->ssp_inactivity_timeout = 5; 506 + user->stp_max_occupancy_timeout = 5; 507 + user->ssp_max_occupancy_timeout = 20; 508 + user->no_outbound_task_timeout = 2; 509 + } 510 + 399 511 static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id) 400 512 { 401 - struct isci_host *isci_host; 513 + struct isci_orom *orom = to_pci_info(pdev)->orom; 514 + struct sci_user_parameters sci_user_params; 515 + u8 oem_version = ISCI_ROM_VER_1_0; 516 + struct isci_host *ihost; 402 517 struct Scsi_Host *shost; 403 - int err; 518 + int err, i; 404 519 405 - isci_host = devm_kzalloc(&pdev->dev, sizeof(*isci_host), GFP_KERNEL); 406 - if (!isci_host) 520 + ihost = devm_kzalloc(&pdev->dev, sizeof(*ihost), GFP_KERNEL); 521 + if (!ihost) 407 522 return NULL; 408 523 409 - isci_host->pdev = pdev; 410 - isci_host->id = id; 524 + ihost->pdev = pdev; 525 + ihost->id = id; 526 + spin_lock_init(&ihost->scic_lock); 527 + init_waitqueue_head(&ihost->eventq); 528 + ihost->sas_ha.dev = &ihost->pdev->dev; 529 + ihost->sas_ha.lldd_ha = ihost; 530 + tasklet_init(&ihost->completion_tasklet, 531 + isci_host_completion_routine, (unsigned long)ihost); 532 + 533 + /* validate module parameters */ 534 + /* TODO: kill struct sci_user_parameters and reference directly */ 535 + sci_oem_defaults(ihost); 536 + isci_user_parameters_get(&sci_user_params); 537 + if (sci_user_parameters_set(ihost, &sci_user_params)) { 538 + dev_warn(&pdev->dev, 539 + "%s: sci_user_parameters_set failed\n", __func__); 540 + return NULL; 541 + } 542 + 543 + /* sanity check platform (or 'firmware') oem parameters */ 544 + if (orom) { 545 + if (id < 0 || id >= SCI_MAX_CONTROLLERS || id > orom->hdr.num_elements) { 546 + dev_warn(&pdev->dev, "parsing firmware oem parameters failed\n"); 547 + return NULL; 548 + } 549 + ihost->oem_parameters = orom->ctrl[id]; 550 + oem_version = orom->hdr.version; 551 + } 552 + 553 + /* validate oem parameters (platform, firmware, or built-in defaults) */ 554 + if (sci_oem_parameters_validate(&ihost->oem_parameters, oem_version)) { 555 + dev_warn(&pdev->dev, "oem parameter validation failed\n"); 556 + return NULL; 557 + } 558 + 559 + for (i = 0; i < SCI_MAX_PORTS; i++) { 560 + struct isci_port *iport = &ihost->ports[i]; 561 + 562 + INIT_LIST_HEAD(&iport->remote_dev_list); 563 + iport->isci_host = ihost; 564 + } 565 + 566 + for (i = 0; i < SCI_MAX_PHYS; i++) 567 + isci_phy_init(&ihost->phys[i], ihost, i); 568 + 569 + for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) { 570 + struct isci_remote_device *idev = &ihost->devices[i]; 571 + 572 + INIT_LIST_HEAD(&idev->node); 573 + } 411 574 412 575 shost = scsi_host_alloc(&isci_sht, sizeof(void *)); 413 576 if (!shost) 414 577 return NULL; 415 - isci_host->shost = shost; 416 578 417 579 dev_info(&pdev->dev, "%sSCU controller %d: phy 3-0 cables: " 418 580 "{%s, %s, %s, %s}\n", 419 - (is_cable_select_overridden() ? "* " : ""), isci_host->id, 420 - lookup_cable_names(decode_cable_selection(isci_host, 3)), 421 - lookup_cable_names(decode_cable_selection(isci_host, 2)), 422 - lookup_cable_names(decode_cable_selection(isci_host, 1)), 423 - lookup_cable_names(decode_cable_selection(isci_host, 0))); 581 + (is_cable_select_overridden() ? "* " : ""), ihost->id, 582 + lookup_cable_names(decode_cable_selection(ihost, 3)), 583 + lookup_cable_names(decode_cable_selection(ihost, 2)), 584 + lookup_cable_names(decode_cable_selection(ihost, 1)), 585 + lookup_cable_names(decode_cable_selection(ihost, 0))); 424 586 425 - err = isci_host_init(isci_host); 587 + err = isci_host_init(ihost); 426 588 if (err) 427 589 goto err_shost; 428 590 429 - SHOST_TO_SAS_HA(shost) = &isci_host->sas_ha; 430 - isci_host->sas_ha.core.shost = shost; 591 + SHOST_TO_SAS_HA(shost) = &ihost->sas_ha; 592 + ihost->sas_ha.core.shost = shost; 431 593 shost->transportt = isci_transport_template; 432 594 433 595 shost->max_id = ~0; ··· 599 439 if (err) 600 440 goto err_shost; 601 441 602 - err = isci_register_sas_ha(isci_host); 442 + err = isci_register_sas_ha(ihost); 603 443 if (err) 604 444 goto err_shost_remove; 605 445 606 - return isci_host; 446 + return ihost; 607 447 608 448 err_shost_remove: 609 449 scsi_remove_host(shost); ··· 636 476 if (!orom) 637 477 orom = isci_request_oprom(pdev); 638 478 639 - for (i = 0; orom && i < ARRAY_SIZE(orom->ctrl); i++) { 479 + for (i = 0; orom && i < num_controllers(pdev); i++) { 640 480 if (sci_oem_parameters_validate(&orom->ctrl[i], 641 481 orom->hdr.version)) { 642 482 dev_warn(&pdev->dev, ··· 685 525 pci_info->hosts[i] = h; 686 526 687 527 /* turn on DIF support */ 688 - scsi_host_set_prot(h->shost, 528 + scsi_host_set_prot(to_shost(h), 689 529 SHOST_DIF_TYPE1_PROTECTION | 690 530 SHOST_DIF_TYPE2_PROTECTION | 691 531 SHOST_DIF_TYPE3_PROTECTION); 692 - scsi_host_set_guard(h->shost, SHOST_DIX_GUARD_CRC); 532 + scsi_host_set_guard(to_shost(h), SHOST_DIX_GUARD_CRC); 693 533 } 694 534 695 535 err = isci_setup_interrupts(pdev); ··· 697 537 goto err_host_alloc; 698 538 699 539 for_each_isci_host(i, isci_host, pdev) 700 - scsi_scan_host(isci_host->shost); 540 + scsi_scan_host(to_shost(isci_host)); 701 541 702 542 return 0; 703 543
+70 -6
drivers/scsi/isci/phy.c
··· 580 580 581 581 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SAS_SPEED_EN); 582 582 583 - iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS; 583 + iphy->protocol = SAS_PROTOCOL_SSP; 584 584 } 585 585 586 586 static void sci_phy_start_sata_link_training(struct isci_phy *iphy) ··· 591 591 */ 592 592 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_POWER); 593 593 594 - iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA; 594 + iphy->protocol = SAS_PROTOCOL_SATA; 595 595 } 596 596 597 597 /** ··· 668 668 phy_to_host(iphy)->id, iphy->phy_index, \ 669 669 phy_state_name(state), phy_event_name(code), code) 670 670 671 + 672 + void scu_link_layer_set_txcomsas_timeout(struct isci_phy *iphy, u32 timeout) 673 + { 674 + u32 val; 675 + 676 + /* Extend timeout */ 677 + val = readl(&iphy->link_layer_registers->transmit_comsas_signal); 678 + val &= ~SCU_SAS_LLTXCOMSAS_GEN_VAL(NEGTIME, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_MASK); 679 + val |= SCU_SAS_LLTXCOMSAS_GEN_VAL(NEGTIME, timeout); 680 + 681 + writel(val, &iphy->link_layer_registers->transmit_comsas_signal); 682 + } 683 + 671 684 enum sci_status sci_phy_event_handler(struct isci_phy *iphy, u32 event_code) 672 685 { 673 686 enum sci_phy_states state = iphy->sm.current_state_id; ··· 696 683 sci_phy_start_sata_link_training(iphy); 697 684 iphy->is_in_link_training = true; 698 685 break; 686 + case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT: 687 + /* Extend timeout value */ 688 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_EXTENDED); 689 + 690 + /* Start the oob/sn state machine over again */ 691 + sci_change_state(&iphy->sm, SCI_PHY_STARTING); 692 + break; 699 693 default: 700 694 phy_event_dbg(iphy, state, event_code); 701 695 return SCI_FAILURE; ··· 737 717 sci_phy_start_sata_link_training(iphy); 738 718 break; 739 719 case SCU_EVENT_LINK_FAILURE: 720 + /* Change the timeout value to default */ 721 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_DEFAULT); 722 + 740 723 /* Link failure change state back to the starting state */ 741 724 sci_change_state(&iphy->sm, SCI_PHY_STARTING); 742 725 break; 726 + case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT: 727 + /* Extend the timeout value */ 728 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_EXTENDED); 729 + 730 + /* Start the oob/sn state machine over again */ 731 + sci_change_state(&iphy->sm, SCI_PHY_STARTING); 732 + break; 743 733 default: 744 734 phy_event_warn(iphy, state, event_code); 745 735 return SCI_FAILURE; ··· 770 740 sci_phy_start_sata_link_training(iphy); 771 741 break; 772 742 case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT: 743 + /* Extend the timeout value */ 744 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_EXTENDED); 745 + 746 + /* Start the oob/sn state machine over again */ 747 + sci_change_state(&iphy->sm, SCI_PHY_STARTING); 748 + break; 773 749 case SCU_EVENT_LINK_FAILURE: 750 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_DEFAULT); 774 751 case SCU_EVENT_HARD_RESET_RECEIVED: 775 752 /* Start the oob/sn state machine over again */ 776 753 sci_change_state(&iphy->sm, SCI_PHY_STARTING); ··· 790 753 case SCI_PHY_SUB_AWAIT_SAS_POWER: 791 754 switch (scu_get_event_code(event_code)) { 792 755 case SCU_EVENT_LINK_FAILURE: 756 + /* Change the timeout value to default */ 757 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_DEFAULT); 758 + 793 759 /* Link failure change state back to the starting state */ 794 760 sci_change_state(&iphy->sm, SCI_PHY_STARTING); 795 761 break; ··· 804 764 case SCI_PHY_SUB_AWAIT_SATA_POWER: 805 765 switch (scu_get_event_code(event_code)) { 806 766 case SCU_EVENT_LINK_FAILURE: 767 + /* Change the timeout value to default */ 768 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_DEFAULT); 769 + 807 770 /* Link failure change state back to the starting state */ 808 771 sci_change_state(&iphy->sm, SCI_PHY_STARTING); 809 772 break; ··· 831 788 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN: 832 789 switch (scu_get_event_code(event_code)) { 833 790 case SCU_EVENT_LINK_FAILURE: 791 + /* Change the timeout value to default */ 792 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_DEFAULT); 793 + 834 794 /* Link failure change state back to the starting state */ 835 795 sci_change_state(&iphy->sm, SCI_PHY_STARTING); 836 796 break; ··· 843 797 */ 844 798 break; 845 799 case SCU_EVENT_SATA_PHY_DETECTED: 846 - iphy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA; 800 + iphy->protocol = SAS_PROTOCOL_SATA; 847 801 848 802 /* We have received the SATA PHY notification change state */ 849 803 sci_change_state(&iphy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN); ··· 882 836 SCI_PHY_SUB_AWAIT_SIG_FIS_UF); 883 837 break; 884 838 case SCU_EVENT_LINK_FAILURE: 839 + /* Change the timeout value to default */ 840 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_DEFAULT); 841 + 885 842 /* Link failure change state back to the starting state */ 886 843 sci_change_state(&iphy->sm, SCI_PHY_STARTING); 887 844 break; ··· 908 859 break; 909 860 910 861 case SCU_EVENT_LINK_FAILURE: 862 + /* Change the timeout value to default */ 863 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_DEFAULT); 864 + 911 865 /* Link failure change state back to the starting state */ 912 866 sci_change_state(&iphy->sm, SCI_PHY_STARTING); 913 867 break; ··· 923 871 case SCI_PHY_READY: 924 872 switch (scu_get_event_code(event_code)) { 925 873 case SCU_EVENT_LINK_FAILURE: 874 + /* Set default timeout */ 875 + scu_link_layer_set_txcomsas_timeout(iphy, SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_DEFAULT); 876 + 926 877 /* Link failure change state back to the starting state */ 927 878 sci_change_state(&iphy->sm, SCI_PHY_STARTING); 928 879 break; 929 880 case SCU_EVENT_BROADCAST_CHANGE: 881 + case SCU_EVENT_BROADCAST_SES: 882 + case SCU_EVENT_BROADCAST_RESERVED0: 883 + case SCU_EVENT_BROADCAST_RESERVED1: 884 + case SCU_EVENT_BROADCAST_EXPANDER: 885 + case SCU_EVENT_BROADCAST_AEN: 930 886 /* Broadcast change received. Notify the port. */ 931 887 if (phy_get_non_dummy_port(iphy) != NULL) 932 888 sci_port_broadcast_change_received(iphy->owning_port, iphy); 933 889 else 934 890 iphy->bcn_received_while_port_unassigned = true; 935 891 break; 892 + case SCU_EVENT_BROADCAST_RESERVED3: 893 + case SCU_EVENT_BROADCAST_RESERVED4: 936 894 default: 937 895 phy_event_warn(iphy, state, event_code); 938 896 return SCI_FAILURE_INVALID_STATE; ··· 1277 1215 scu_link_layer_start_oob(iphy); 1278 1216 1279 1217 /* We don't know what kind of phy we are going to be just yet */ 1280 - iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN; 1218 + iphy->protocol = SAS_PROTOCOL_NONE; 1281 1219 iphy->bcn_received_while_port_unassigned = false; 1282 1220 1283 1221 if (iphy->sm.previous_state_id == SCI_PHY_READY) ··· 1312 1250 */ 1313 1251 sci_port_deactivate_phy(iphy->owning_port, iphy, false); 1314 1252 1315 - if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) { 1253 + if (iphy->protocol == SAS_PROTOCOL_SSP) { 1316 1254 scu_link_layer_tx_hard_reset(iphy); 1317 1255 } else { 1318 1256 /* The SCU does not need to have a discrete reset state so ··· 1378 1316 iphy->owning_port = iport; 1379 1317 iphy->phy_index = phy_index; 1380 1318 iphy->bcn_received_while_port_unassigned = false; 1381 - iphy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN; 1319 + iphy->protocol = SAS_PROTOCOL_NONE; 1382 1320 iphy->link_layer_registers = NULL; 1383 1321 iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN; 1384 1322 ··· 1442 1380 switch (func) { 1443 1381 case PHY_FUNC_DISABLE: 1444 1382 spin_lock_irqsave(&ihost->scic_lock, flags); 1383 + scu_link_layer_start_oob(iphy); 1445 1384 sci_phy_stop(iphy); 1446 1385 spin_unlock_irqrestore(&ihost->scic_lock, flags); 1447 1386 break; 1448 1387 1449 1388 case PHY_FUNC_LINK_RESET: 1450 1389 spin_lock_irqsave(&ihost->scic_lock, flags); 1390 + scu_link_layer_start_oob(iphy); 1451 1391 sci_phy_stop(iphy); 1452 1392 sci_phy_start(iphy); 1453 1393 spin_unlock_irqrestore(&ihost->scic_lock, flags);
+1 -8
drivers/scsi/isci/phy.h
··· 76 76 */ 77 77 #define SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT 250 78 78 79 - enum sci_phy_protocol { 80 - SCIC_SDS_PHY_PROTOCOL_UNKNOWN, 81 - SCIC_SDS_PHY_PROTOCOL_SAS, 82 - SCIC_SDS_PHY_PROTOCOL_SATA, 83 - SCIC_SDS_MAX_PHY_PROTOCOLS 84 - }; 85 - 86 79 /** 87 80 * isci_phy - hba local phy infrastructure 88 81 * @sm: ··· 88 95 struct sci_base_state_machine sm; 89 96 struct isci_port *owning_port; 90 97 enum sas_linkrate max_negotiated_speed; 91 - enum sci_phy_protocol protocol; 98 + enum sas_protocol protocol; 92 99 u8 phy_index; 93 100 bool bcn_received_while_port_unassigned; 94 101 bool is_in_link_training;
+37 -31
drivers/scsi/isci/port.c
··· 184 184 185 185 sci_port_get_properties(iport, &properties); 186 186 187 - if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) { 187 + if (iphy->protocol == SAS_PROTOCOL_SATA) { 188 188 u64 attached_sas_address; 189 189 190 190 iphy->sas_phy.oob_mode = SATA_OOB_MODE; ··· 204 204 205 205 memcpy(&iphy->sas_phy.attached_sas_addr, 206 206 &attached_sas_address, sizeof(attached_sas_address)); 207 - } else if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) { 207 + } else if (iphy->protocol == SAS_PROTOCOL_SSP) { 208 208 iphy->sas_phy.oob_mode = SAS_OOB_MODE; 209 209 iphy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame); 210 210 ··· 251 251 if (isci_phy->sas_phy.port && 252 252 isci_phy->sas_phy.port->num_phys == 1) { 253 253 /* change the state for all devices on this port. The 254 - * next task sent to this device will be returned as 255 - * SAS_TASK_UNDELIVERED, and the scsi mid layer will 256 - * remove the target 257 - */ 254 + * next task sent to this device will be returned as 255 + * SAS_TASK_UNDELIVERED, and the scsi mid layer will 256 + * remove the target 257 + */ 258 258 list_for_each_entry(isci_device, 259 259 &isci_port->remote_dev_list, 260 260 node) { ··· 517 517 */ 518 518 iphy = sci_port_get_a_connected_phy(iport); 519 519 if (iphy) { 520 - if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) { 520 + if (iphy->protocol != SAS_PROTOCOL_SATA) { 521 521 sci_phy_get_attached_sas_address(iphy, sas); 522 522 } else { 523 523 sci_phy_get_sas_address(iphy, sas); ··· 624 624 { 625 625 struct isci_host *ihost = iport->owning_controller; 626 626 627 - if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA && (flags & PF_RESUME)) 627 + if (iphy->protocol != SAS_PROTOCOL_SATA && (flags & PF_RESUME)) 628 628 sci_phy_resume(iphy); 629 629 630 630 iport->active_phy_mask |= 1 << iphy->phy_index; ··· 751 751 * wide ports and direct attached phys. Since there are no wide ported SATA 752 752 * devices this could become an invalid port configuration. 753 753 */ 754 - bool sci_port_link_detected( 755 - struct isci_port *iport, 756 - struct isci_phy *iphy) 754 + bool sci_port_link_detected(struct isci_port *iport, struct isci_phy *iphy) 757 755 { 758 756 if ((iport->logical_port_index != SCIC_SDS_DUMMY_PORT) && 759 - (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA)) { 757 + (iphy->protocol == SAS_PROTOCOL_SATA)) { 760 758 if (sci_port_is_wide(iport)) { 761 759 sci_port_invalid_link_up(iport, iphy); 762 760 return false; ··· 1199 1201 enum sci_status status; 1200 1202 enum sci_port_states state; 1201 1203 1204 + sci_port_bcn_enable(iport); 1205 + 1202 1206 state = iport->sm.current_state_id; 1203 1207 switch (state) { 1204 1208 case SCI_PORT_STOPPED: { ··· 1548 1548 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT); 1549 1549 } 1550 1550 1551 + void sci_port_set_hang_detection_timeout(struct isci_port *iport, u32 timeout) 1552 + { 1553 + int phy_index; 1554 + u32 phy_mask = iport->active_phy_mask; 1555 + 1556 + if (timeout) 1557 + ++iport->hang_detect_users; 1558 + else if (iport->hang_detect_users > 1) 1559 + --iport->hang_detect_users; 1560 + else 1561 + iport->hang_detect_users = 0; 1562 + 1563 + if (timeout || (iport->hang_detect_users == 0)) { 1564 + for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++) { 1565 + if ((phy_mask >> phy_index) & 1) { 1566 + writel(timeout, 1567 + &iport->phy_table[phy_index] 1568 + ->link_layer_registers 1569 + ->link_layer_hang_detection_timeout); 1570 + } 1571 + } 1572 + } 1573 + } 1551 1574 /* --------------------------------------------------------------------------- */ 1552 1575 1553 1576 static const struct sci_base_state sci_port_state_table[] = { ··· 1619 1596 1620 1597 iport->started_request_count = 0; 1621 1598 iport->assigned_device_count = 0; 1599 + iport->hang_detect_users = 0; 1622 1600 1623 1601 iport->reserved_rni = SCU_DUMMY_INDEX; 1624 1602 iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG; ··· 1630 1606 1631 1607 for (index = 0; index < SCI_MAX_PHYS; index++) 1632 1608 iport->phy_table[index] = NULL; 1633 - } 1634 - 1635 - void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index) 1636 - { 1637 - INIT_LIST_HEAD(&iport->remote_dev_list); 1638 - INIT_LIST_HEAD(&iport->domain_dev_list); 1639 - iport->isci_host = ihost; 1640 1609 } 1641 1610 1642 1611 void sci_port_broadcast_change_received(struct isci_port *iport, struct isci_phy *iphy) ··· 1687 1670 " failed 0x%x\n", 1688 1671 __func__, iport, status); 1689 1672 1690 - } 1691 - 1692 - /* If the hard reset for the port has failed, consider this 1693 - * the same as link failures on all phys in the port. 1694 - */ 1695 - if (ret != TMF_RESP_FUNC_COMPLETE) { 1696 - 1697 - dev_err(&ihost->pdev->dev, 1698 - "%s: iport = %p; hard reset failed " 1699 - "(0x%x) - driving explicit link fail for all phys\n", 1700 - __func__, iport, iport->hard_reset_status); 1701 1673 } 1702 1674 return ret; 1703 1675 } ··· 1746 1740 struct isci_host *ihost = phy->ha->lldd_ha; 1747 1741 struct isci_phy *iphy = to_iphy(phy); 1748 1742 struct asd_sas_port *port = phy->port; 1749 - struct isci_port *iport; 1743 + struct isci_port *iport = NULL; 1750 1744 unsigned long flags; 1751 1745 int i; 1752 1746
+5 -6
drivers/scsi/isci/port.h
··· 97 97 struct isci_port { 98 98 struct isci_host *isci_host; 99 99 struct list_head remote_dev_list; 100 - struct list_head domain_dev_list; 101 100 #define IPORT_RESET_PENDING 0 102 101 unsigned long state; 103 102 enum sci_status hard_reset_status; ··· 111 112 u16 reserved_tag; 112 113 u32 started_request_count; 113 114 u32 assigned_device_count; 115 + u32 hang_detect_users; 114 116 u32 not_ready_reason; 115 117 struct isci_phy *phy_table[SCI_MAX_PHYS]; 116 118 struct isci_host *owning_controller; ··· 270 270 struct isci_port *iport, 271 271 struct sci_sas_address *sas_address); 272 272 273 + void sci_port_set_hang_detection_timeout( 274 + struct isci_port *isci_port, 275 + u32 timeout); 276 + 273 277 void isci_port_formed(struct asd_sas_phy *); 274 278 void isci_port_deformed(struct asd_sas_phy *); 275 - 276 - void isci_port_init( 277 - struct isci_port *port, 278 - struct isci_host *host, 279 - int index); 280 279 281 280 int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport, 282 281 struct isci_phy *iphy);
+11 -7
drivers/scsi/isci/port_config.c
··· 57 57 58 58 #define SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT (10) 59 59 #define SCIC_SDS_APC_RECONFIGURATION_TIMEOUT (10) 60 - #define SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION (250) 60 + #define SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION (1000) 61 61 62 62 enum SCIC_SDS_APC_ACTIVITY { 63 63 SCIC_SDS_APC_SKIP_PHY, ··· 472 472 * down event or a link up event where we can not yet tell to which a phy 473 473 * belongs. 474 474 */ 475 - static void sci_apc_agent_start_timer( 476 - struct sci_port_configuration_agent *port_agent, 477 - u32 timeout) 475 + static void sci_apc_agent_start_timer(struct sci_port_configuration_agent *port_agent, 476 + u32 timeout) 478 477 { 479 - if (port_agent->timer_pending) 480 - sci_del_timer(&port_agent->timer); 481 - 482 478 port_agent->timer_pending = true; 483 479 sci_mod_timer(&port_agent->timer, timeout); 484 480 } ··· 693 697 &ihost->phys[index], false); 694 698 } 695 699 700 + if (is_controller_start_complete(ihost)) 701 + sci_controller_transition_to_ready(ihost, SCI_SUCCESS); 702 + 696 703 done: 697 704 spin_unlock_irqrestore(&ihost->scic_lock, flags); 698 705 } ··· 729 730 port_agent->phy_valid_port_range[index].min_index = 0; 730 731 port_agent->phy_valid_port_range[index].max_index = 0; 731 732 } 733 + } 734 + 735 + bool is_port_config_apc(struct isci_host *ihost) 736 + { 737 + return ihost->port_agent.link_up_handler == sci_apc_agent_link_up; 732 738 } 733 739 734 740 enum sci_status sci_port_configuration_agent_initialize(
-12
drivers/scsi/isci/probe_roms.c
··· 112 112 return rom; 113 113 } 114 114 115 - enum sci_status isci_parse_oem_parameters(struct sci_oem_params *oem, 116 - struct isci_orom *orom, int scu_index) 117 - { 118 - /* check for valid inputs */ 119 - if (scu_index < 0 || scu_index >= SCI_MAX_CONTROLLERS || 120 - scu_index > orom->hdr.num_elements || !oem) 121 - return -EINVAL; 122 - 123 - *oem = orom->ctrl[scu_index]; 124 - return 0; 125 - } 126 - 127 115 struct isci_orom *isci_request_firmware(struct pci_dev *pdev, const struct firmware *fw) 128 116 { 129 117 struct isci_orom *orom = NULL, *data;
-2
drivers/scsi/isci/probe_roms.h
··· 156 156 157 157 struct isci_orom; 158 158 struct isci_orom *isci_request_oprom(struct pci_dev *pdev); 159 - enum sci_status isci_parse_oem_parameters(struct sci_oem_params *oem, 160 - struct isci_orom *orom, int scu_index); 161 159 struct isci_orom *isci_request_firmware(struct pci_dev *pdev, const struct firmware *fw); 162 160 struct isci_orom *isci_get_efi_var(struct pci_dev *pdev); 163 161
+8
drivers/scsi/isci/registers.h
··· 1239 1239 #define SCU_SAS_LLCTL_GEN_BIT(name) \ 1240 1240 SCU_GEN_BIT(SCU_SAS_LINK_LAYER_CONTROL_ ## name) 1241 1241 1242 + #define SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_DEFAULT (0xF0) 1243 + #define SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_EXTENDED (0x1FF) 1244 + #define SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_SHIFT (0) 1245 + #define SCU_SAS_LINK_LAYER_TXCOMSAS_NEGTIME_MASK (0x3FF) 1246 + 1247 + #define SCU_SAS_LLTXCOMSAS_GEN_VAL(name, value) \ 1248 + SCU_GEN_VALUE(SCU_SAS_LINK_LAYER_TXCOMSAS_ ## name, value) 1249 + 1242 1250 1243 1251 /* #define SCU_FRXHECR_DCNT_OFFSET 0x00B0 */ 1244 1252 #define SCU_PSZGCR_OFFSET 0x00E4
+439 -149
drivers/scsi/isci/remote_device.c
··· 72 72 } 73 73 #undef C 74 74 75 - /** 76 - * isci_remote_device_not_ready() - This function is called by the ihost when 77 - * the remote device is not ready. We mark the isci device as ready (not 78 - * "ready_for_io") and signal the waiting proccess. 79 - * @isci_host: This parameter specifies the isci host object. 80 - * @isci_device: This parameter specifies the remote device 81 - * 82 - * sci_lock is held on entrance to this function. 83 - */ 84 - static void isci_remote_device_not_ready(struct isci_host *ihost, 85 - struct isci_remote_device *idev, u32 reason) 75 + enum sci_status sci_remote_device_suspend(struct isci_remote_device *idev, 76 + enum sci_remote_node_suspension_reasons reason) 86 77 { 87 - struct isci_request *ireq; 88 - 89 - dev_dbg(&ihost->pdev->dev, 90 - "%s: isci_device = %p\n", __func__, idev); 91 - 92 - switch (reason) { 93 - case SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED: 94 - set_bit(IDEV_GONE, &idev->flags); 95 - break; 96 - case SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED: 97 - set_bit(IDEV_IO_NCQERROR, &idev->flags); 98 - 99 - /* Kill all outstanding requests for the device. */ 100 - list_for_each_entry(ireq, &idev->reqs_in_process, dev_node) { 101 - 102 - dev_dbg(&ihost->pdev->dev, 103 - "%s: isci_device = %p request = %p\n", 104 - __func__, idev, ireq); 105 - 106 - sci_controller_terminate_request(ihost, 107 - idev, 108 - ireq); 109 - } 110 - /* Fall through into the default case... */ 111 - default: 112 - clear_bit(IDEV_IO_READY, &idev->flags); 113 - break; 114 - } 78 + return sci_remote_node_context_suspend(&idev->rnc, reason, 79 + SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT); 115 80 } 116 81 117 82 /** ··· 98 133 wake_up(&ihost->eventq); 99 134 } 100 135 136 + static enum sci_status sci_remote_device_terminate_req( 137 + struct isci_host *ihost, 138 + struct isci_remote_device *idev, 139 + int check_abort, 140 + struct isci_request *ireq) 141 + { 142 + if (!test_bit(IREQ_ACTIVE, &ireq->flags) || 143 + (ireq->target_device != idev) || 144 + (check_abort && !test_bit(IREQ_PENDING_ABORT, &ireq->flags))) 145 + return SCI_SUCCESS; 146 + 147 + dev_dbg(&ihost->pdev->dev, 148 + "%s: idev=%p; flags=%lx; req=%p; req target=%p\n", 149 + __func__, idev, idev->flags, ireq, ireq->target_device); 150 + 151 + set_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags); 152 + 153 + return sci_controller_terminate_request(ihost, idev, ireq); 154 + } 155 + 156 + static enum sci_status sci_remote_device_terminate_reqs_checkabort( 157 + struct isci_remote_device *idev, 158 + int chk) 159 + { 160 + struct isci_host *ihost = idev->owning_port->owning_controller; 161 + enum sci_status status = SCI_SUCCESS; 162 + u32 i; 163 + 164 + for (i = 0; i < SCI_MAX_IO_REQUESTS; i++) { 165 + struct isci_request *ireq = ihost->reqs[i]; 166 + enum sci_status s; 167 + 168 + s = sci_remote_device_terminate_req(ihost, idev, chk, ireq); 169 + if (s != SCI_SUCCESS) 170 + status = s; 171 + } 172 + return status; 173 + } 174 + 175 + static bool isci_compare_suspendcount( 176 + struct isci_remote_device *idev, 177 + u32 localcount) 178 + { 179 + smp_rmb(); 180 + 181 + /* Check for a change in the suspend count, or the RNC 182 + * being destroyed. 183 + */ 184 + return (localcount != idev->rnc.suspend_count) 185 + || sci_remote_node_context_is_being_destroyed(&idev->rnc); 186 + } 187 + 188 + static bool isci_check_reqterm( 189 + struct isci_host *ihost, 190 + struct isci_remote_device *idev, 191 + struct isci_request *ireq, 192 + u32 localcount) 193 + { 194 + unsigned long flags; 195 + bool res; 196 + 197 + spin_lock_irqsave(&ihost->scic_lock, flags); 198 + res = isci_compare_suspendcount(idev, localcount) 199 + && !test_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags); 200 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 201 + 202 + return res; 203 + } 204 + 205 + static bool isci_check_devempty( 206 + struct isci_host *ihost, 207 + struct isci_remote_device *idev, 208 + u32 localcount) 209 + { 210 + unsigned long flags; 211 + bool res; 212 + 213 + spin_lock_irqsave(&ihost->scic_lock, flags); 214 + res = isci_compare_suspendcount(idev, localcount) 215 + && idev->started_request_count == 0; 216 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 217 + 218 + return res; 219 + } 220 + 221 + enum sci_status isci_remote_device_terminate_requests( 222 + struct isci_host *ihost, 223 + struct isci_remote_device *idev, 224 + struct isci_request *ireq) 225 + { 226 + enum sci_status status = SCI_SUCCESS; 227 + unsigned long flags; 228 + u32 rnc_suspend_count; 229 + 230 + spin_lock_irqsave(&ihost->scic_lock, flags); 231 + 232 + if (isci_get_device(idev) == NULL) { 233 + dev_dbg(&ihost->pdev->dev, "%s: failed isci_get_device(idev=%p)\n", 234 + __func__, idev); 235 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 236 + status = SCI_FAILURE; 237 + } else { 238 + /* If already suspended, don't wait for another suspension. */ 239 + smp_rmb(); 240 + rnc_suspend_count 241 + = sci_remote_node_context_is_suspended(&idev->rnc) 242 + ? 0 : idev->rnc.suspend_count; 243 + 244 + dev_dbg(&ihost->pdev->dev, 245 + "%s: idev=%p, ireq=%p; started_request_count=%d, " 246 + "rnc_suspend_count=%d, rnc.suspend_count=%d" 247 + "about to wait\n", 248 + __func__, idev, ireq, idev->started_request_count, 249 + rnc_suspend_count, idev->rnc.suspend_count); 250 + 251 + #define MAX_SUSPEND_MSECS 10000 252 + if (ireq) { 253 + /* Terminate a specific TC. */ 254 + set_bit(IREQ_NO_AUTO_FREE_TAG, &ireq->flags); 255 + sci_remote_device_terminate_req(ihost, idev, 0, ireq); 256 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 257 + if (!wait_event_timeout(ihost->eventq, 258 + isci_check_reqterm(ihost, idev, ireq, 259 + rnc_suspend_count), 260 + msecs_to_jiffies(MAX_SUSPEND_MSECS))) { 261 + 262 + dev_warn(&ihost->pdev->dev, "%s host%d timeout single\n", 263 + __func__, ihost->id); 264 + dev_dbg(&ihost->pdev->dev, 265 + "%s: ******* Timeout waiting for " 266 + "suspend; idev=%p, current state %s; " 267 + "started_request_count=%d, flags=%lx\n\t" 268 + "rnc_suspend_count=%d, rnc.suspend_count=%d " 269 + "RNC: current state %s, current " 270 + "suspend_type %x dest state %d;\n" 271 + "ireq=%p, ireq->flags = %lx\n", 272 + __func__, idev, 273 + dev_state_name(idev->sm.current_state_id), 274 + idev->started_request_count, idev->flags, 275 + rnc_suspend_count, idev->rnc.suspend_count, 276 + rnc_state_name(idev->rnc.sm.current_state_id), 277 + idev->rnc.suspend_type, 278 + idev->rnc.destination_state, 279 + ireq, ireq->flags); 280 + } 281 + spin_lock_irqsave(&ihost->scic_lock, flags); 282 + clear_bit(IREQ_NO_AUTO_FREE_TAG, &ireq->flags); 283 + if (!test_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags)) 284 + isci_free_tag(ihost, ireq->io_tag); 285 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 286 + } else { 287 + /* Terminate all TCs. */ 288 + sci_remote_device_terminate_requests(idev); 289 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 290 + if (!wait_event_timeout(ihost->eventq, 291 + isci_check_devempty(ihost, idev, 292 + rnc_suspend_count), 293 + msecs_to_jiffies(MAX_SUSPEND_MSECS))) { 294 + 295 + dev_warn(&ihost->pdev->dev, "%s host%d timeout all\n", 296 + __func__, ihost->id); 297 + dev_dbg(&ihost->pdev->dev, 298 + "%s: ******* Timeout waiting for " 299 + "suspend; idev=%p, current state %s; " 300 + "started_request_count=%d, flags=%lx\n\t" 301 + "rnc_suspend_count=%d, " 302 + "RNC: current state %s, " 303 + "rnc.suspend_count=%d, current " 304 + "suspend_type %x dest state %d\n", 305 + __func__, idev, 306 + dev_state_name(idev->sm.current_state_id), 307 + idev->started_request_count, idev->flags, 308 + rnc_suspend_count, 309 + rnc_state_name(idev->rnc.sm.current_state_id), 310 + idev->rnc.suspend_count, 311 + idev->rnc.suspend_type, 312 + idev->rnc.destination_state); 313 + } 314 + } 315 + dev_dbg(&ihost->pdev->dev, "%s: idev=%p, wait done\n", 316 + __func__, idev); 317 + isci_put_device(idev); 318 + } 319 + return status; 320 + } 321 + 322 + /** 323 + * isci_remote_device_not_ready() - This function is called by the ihost when 324 + * the remote device is not ready. We mark the isci device as ready (not 325 + * "ready_for_io") and signal the waiting proccess. 326 + * @isci_host: This parameter specifies the isci host object. 327 + * @isci_device: This parameter specifies the remote device 328 + * 329 + * sci_lock is held on entrance to this function. 330 + */ 331 + static void isci_remote_device_not_ready(struct isci_host *ihost, 332 + struct isci_remote_device *idev, 333 + u32 reason) 334 + { 335 + dev_dbg(&ihost->pdev->dev, 336 + "%s: isci_device = %p; reason = %d\n", __func__, idev, reason); 337 + 338 + switch (reason) { 339 + case SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED: 340 + set_bit(IDEV_IO_NCQERROR, &idev->flags); 341 + 342 + /* Suspend the remote device so the I/O can be terminated. */ 343 + sci_remote_device_suspend(idev, SCI_SW_SUSPEND_NORMAL); 344 + 345 + /* Kill all outstanding requests for the device. */ 346 + sci_remote_device_terminate_requests(idev); 347 + 348 + /* Fall through into the default case... */ 349 + default: 350 + clear_bit(IDEV_IO_READY, &idev->flags); 351 + break; 352 + } 353 + } 354 + 101 355 /* called once the remote node context is ready to be freed. 102 356 * The remote device can now report that its stop operation is complete. none 103 357 */ ··· 328 144 sci_change_state(&idev->sm, SCI_DEV_STOPPED); 329 145 } 330 146 331 - static enum sci_status sci_remote_device_terminate_requests(struct isci_remote_device *idev) 147 + enum sci_status sci_remote_device_terminate_requests( 148 + struct isci_remote_device *idev) 332 149 { 333 - struct isci_host *ihost = idev->owning_port->owning_controller; 334 - enum sci_status status = SCI_SUCCESS; 335 - u32 i; 336 - 337 - for (i = 0; i < SCI_MAX_IO_REQUESTS; i++) { 338 - struct isci_request *ireq = ihost->reqs[i]; 339 - enum sci_status s; 340 - 341 - if (!test_bit(IREQ_ACTIVE, &ireq->flags) || 342 - ireq->target_device != idev) 343 - continue; 344 - 345 - s = sci_controller_terminate_request(ihost, idev, ireq); 346 - if (s != SCI_SUCCESS) 347 - status = s; 348 - } 349 - 350 - return status; 150 + return sci_remote_device_terminate_reqs_checkabort(idev, 0); 351 151 } 352 152 353 153 enum sci_status sci_remote_device_stop(struct isci_remote_device *idev, ··· 369 201 case SCI_SMP_DEV_IDLE: 370 202 case SCI_SMP_DEV_CMD: 371 203 sci_change_state(sm, SCI_DEV_STOPPING); 372 - if (idev->started_request_count == 0) { 204 + if (idev->started_request_count == 0) 373 205 sci_remote_node_context_destruct(&idev->rnc, 374 - rnc_destruct_done, idev); 375 - return SCI_SUCCESS; 376 - } else 377 - return sci_remote_device_terminate_requests(idev); 378 - break; 206 + rnc_destruct_done, 207 + idev); 208 + else { 209 + sci_remote_device_suspend( 210 + idev, SCI_SW_SUSPEND_LINKHANG_DETECT); 211 + sci_remote_device_terminate_requests(idev); 212 + } 213 + return SCI_SUCCESS; 379 214 case SCI_DEV_STOPPING: 380 215 /* All requests should have been terminated, but if there is an 381 216 * attempt to stop a device already in the stopping state, then ··· 434 263 435 264 sci_change_state(sm, SCI_DEV_READY); 436 265 return SCI_SUCCESS; 437 - } 438 - 439 - enum sci_status sci_remote_device_suspend(struct isci_remote_device *idev, 440 - u32 suspend_type) 441 - { 442 - struct sci_base_state_machine *sm = &idev->sm; 443 - enum sci_remote_device_states state = sm->current_state_id; 444 - 445 - if (state != SCI_STP_DEV_CMD) { 446 - dev_warn(scirdev_to_dev(idev), "%s: in wrong state: %s\n", 447 - __func__, dev_state_name(state)); 448 - return SCI_FAILURE_INVALID_STATE; 449 - } 450 - 451 - return sci_remote_node_context_suspend(&idev->rnc, 452 - suspend_type, NULL, NULL); 453 266 } 454 267 455 268 enum sci_status sci_remote_device_frame_handler(struct isci_remote_device *idev, ··· 567 412 enum sci_status sci_remote_device_event_handler(struct isci_remote_device *idev, 568 413 u32 event_code) 569 414 { 415 + enum sci_status status; 570 416 struct sci_base_state_machine *sm = &idev->sm; 571 417 enum sci_remote_device_states state = sm->current_state_id; 572 - enum sci_status status; 573 418 574 419 switch (scu_get_event_type(event_code)) { 575 420 case SCU_EVENT_TYPE_RNC_OPS_MISC: ··· 582 427 status = SCI_SUCCESS; 583 428 584 429 /* Suspend the associated RNC */ 585 - sci_remote_node_context_suspend(&idev->rnc, 586 - SCI_SOFTWARE_SUSPENSION, 587 - NULL, NULL); 430 + sci_remote_device_suspend(idev, SCI_SW_SUSPEND_NORMAL); 588 431 589 432 dev_dbg(scirdev_to_dev(idev), 590 433 "%s: device: %p event code: %x: %s\n", ··· 608 455 if (status != SCI_SUCCESS) 609 456 return status; 610 457 458 + /* Decode device-specific states that may require an RNC resume during 459 + * normal operation. When the abort path is active, these resumes are 460 + * managed when the abort path exits. 461 + */ 611 462 if (state == SCI_STP_DEV_ATAPI_ERROR) { 612 463 /* For ATAPI error state resume the RNC right away. */ 613 464 if (scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX || ··· 900 743 if (status != SCI_SUCCESS) 901 744 return status; 902 745 903 - status = sci_remote_node_context_start_task(&idev->rnc, ireq); 904 - if (status != SCI_SUCCESS) 905 - goto out; 906 - 907 746 status = sci_request_start(ireq); 908 747 if (status != SCI_SUCCESS) 909 748 goto out; ··· 918 765 * the correct action when the remote node context is suspended 919 766 * and later resumed. 920 767 */ 921 - sci_remote_node_context_suspend(&idev->rnc, 922 - SCI_SOFTWARE_SUSPENSION, NULL, NULL); 923 - sci_remote_node_context_resume(&idev->rnc, 924 - sci_remote_device_continue_request, 925 - idev); 768 + sci_remote_device_suspend(idev, 769 + SCI_SW_SUSPEND_LINKHANG_DETECT); 770 + 771 + status = sci_remote_node_context_start_task(&idev->rnc, ireq, 772 + sci_remote_device_continue_request, idev); 926 773 927 774 out: 928 775 sci_remote_device_start_request(idev, ireq, status); ··· 936 783 if (status != SCI_SUCCESS) 937 784 return status; 938 785 939 - status = sci_remote_node_context_start_task(&idev->rnc, ireq); 786 + /* Resume the RNC as needed: */ 787 + status = sci_remote_node_context_start_task(&idev->rnc, ireq, 788 + NULL, NULL); 940 789 if (status != SCI_SUCCESS) 941 790 break; 942 791 ··· 1047 892 * here should go through isci_remote_device_nuke_requests. 1048 893 * If we hit this condition, we will need a way to complete 1049 894 * io requests in process */ 1050 - BUG_ON(!list_empty(&idev->reqs_in_process)); 895 + BUG_ON(idev->started_request_count > 0); 1051 896 1052 897 sci_remote_device_destruct(idev); 1053 898 list_del_init(&idev->node); ··· 1109 954 static void sci_remote_device_resetting_state_enter(struct sci_base_state_machine *sm) 1110 955 { 1111 956 struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm); 957 + struct isci_host *ihost = idev->owning_port->owning_controller; 1112 958 1113 - sci_remote_node_context_suspend( 1114 - &idev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL); 959 + dev_dbg(&ihost->pdev->dev, 960 + "%s: isci_device = %p\n", __func__, idev); 961 + 962 + sci_remote_device_suspend(idev, SCI_SW_SUSPEND_LINKHANG_DETECT); 1115 963 } 1116 964 1117 965 static void sci_remote_device_resetting_state_exit(struct sci_base_state_machine *sm) 1118 966 { 1119 967 struct isci_remote_device *idev = container_of(sm, typeof(*idev), sm); 968 + struct isci_host *ihost = idev->owning_port->owning_controller; 969 + 970 + dev_dbg(&ihost->pdev->dev, 971 + "%s: isci_device = %p\n", __func__, idev); 1120 972 1121 973 sci_remote_node_context_resume(&idev->rnc, NULL, NULL); 1122 974 } ··· 1275 1113 { 1276 1114 enum sci_status status; 1277 1115 struct sci_port_properties properties; 1278 - struct domain_device *dev = idev->domain_dev; 1279 1116 1280 1117 sci_remote_device_construct(iport, idev); 1281 - 1282 - /* 1283 - * This information is request to determine how many remote node context 1284 - * entries will be needed to store the remote node. 1285 - */ 1286 - idev->is_direct_attached = true; 1287 1118 1288 1119 sci_port_get_properties(iport, &properties); 1289 1120 /* Get accurate port width from port's phy mask for a DA device. */ 1290 1121 idev->device_port_width = hweight32(properties.phy_mask); 1291 1122 1292 1123 status = sci_controller_allocate_remote_node_context(iport->owning_controller, 1293 - idev, 1294 - &idev->rnc.remote_node_index); 1124 + idev, 1125 + &idev->rnc.remote_node_index); 1295 1126 1296 1127 if (status != SCI_SUCCESS) 1297 1128 return status; 1298 - 1299 - if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV || 1300 - (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev)) 1301 - /* pass */; 1302 - else 1303 - return SCI_FAILURE_UNSUPPORTED_PROTOCOL; 1304 1129 1305 1130 idev->connection_rate = sci_port_get_max_allowed_speed(iport); 1306 1131 ··· 1320 1171 if (status != SCI_SUCCESS) 1321 1172 return status; 1322 1173 1323 - if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV || 1324 - (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev)) 1325 - /* pass */; 1326 - else 1327 - return SCI_FAILURE_UNSUPPORTED_PROTOCOL; 1328 - 1329 - /* 1330 - * For SAS-2 the physical link rate is actually a logical link 1174 + /* For SAS-2 the physical link rate is actually a logical link 1331 1175 * rate that incorporates multiplexing. The SCU doesn't 1332 1176 * incorporate multiplexing and for the purposes of the 1333 1177 * connection the logical link rate is that same as the 1334 1178 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay 1335 - * one another, so this code works for both situations. */ 1179 + * one another, so this code works for both situations. 1180 + */ 1336 1181 idev->connection_rate = min_t(u16, sci_port_get_max_allowed_speed(iport), 1337 1182 dev->linkrate); 1338 1183 ··· 1334 1191 idev->device_port_width = 1; 1335 1192 1336 1193 return SCI_SUCCESS; 1194 + } 1195 + 1196 + enum sci_status sci_remote_device_resume( 1197 + struct isci_remote_device *idev, 1198 + scics_sds_remote_node_context_callback cb_fn, 1199 + void *cb_p) 1200 + { 1201 + enum sci_status status; 1202 + 1203 + status = sci_remote_node_context_resume(&idev->rnc, cb_fn, cb_p); 1204 + if (status != SCI_SUCCESS) 1205 + dev_dbg(scirdev_to_dev(idev), "%s: failed to resume: %d\n", 1206 + __func__, status); 1207 + return status; 1208 + } 1209 + 1210 + static void isci_remote_device_resume_from_abort_complete(void *cbparam) 1211 + { 1212 + struct isci_remote_device *idev = cbparam; 1213 + struct isci_host *ihost = idev->owning_port->owning_controller; 1214 + scics_sds_remote_node_context_callback abort_resume_cb = 1215 + idev->abort_resume_cb; 1216 + 1217 + dev_dbg(scirdev_to_dev(idev), "%s: passing-along resume: %p\n", 1218 + __func__, abort_resume_cb); 1219 + 1220 + if (abort_resume_cb != NULL) { 1221 + idev->abort_resume_cb = NULL; 1222 + abort_resume_cb(idev->abort_resume_cbparam); 1223 + } 1224 + clear_bit(IDEV_ABORT_PATH_RESUME_PENDING, &idev->flags); 1225 + wake_up(&ihost->eventq); 1226 + } 1227 + 1228 + static bool isci_remote_device_test_resume_done( 1229 + struct isci_host *ihost, 1230 + struct isci_remote_device *idev) 1231 + { 1232 + unsigned long flags; 1233 + bool done; 1234 + 1235 + spin_lock_irqsave(&ihost->scic_lock, flags); 1236 + done = !test_bit(IDEV_ABORT_PATH_RESUME_PENDING, &idev->flags) 1237 + || test_bit(IDEV_STOP_PENDING, &idev->flags) 1238 + || sci_remote_node_context_is_being_destroyed(&idev->rnc); 1239 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 1240 + 1241 + return done; 1242 + } 1243 + 1244 + void isci_remote_device_wait_for_resume_from_abort( 1245 + struct isci_host *ihost, 1246 + struct isci_remote_device *idev) 1247 + { 1248 + dev_dbg(&ihost->pdev->dev, "%s: starting resume wait: %p\n", 1249 + __func__, idev); 1250 + 1251 + #define MAX_RESUME_MSECS 10000 1252 + if (!wait_event_timeout(ihost->eventq, 1253 + isci_remote_device_test_resume_done(ihost, idev), 1254 + msecs_to_jiffies(MAX_RESUME_MSECS))) { 1255 + 1256 + dev_warn(&ihost->pdev->dev, "%s: #### Timeout waiting for " 1257 + "resume: %p\n", __func__, idev); 1258 + } 1259 + clear_bit(IDEV_ABORT_PATH_RESUME_PENDING, &idev->flags); 1260 + 1261 + dev_dbg(&ihost->pdev->dev, "%s: resume wait done: %p\n", 1262 + __func__, idev); 1263 + } 1264 + 1265 + enum sci_status isci_remote_device_resume_from_abort( 1266 + struct isci_host *ihost, 1267 + struct isci_remote_device *idev) 1268 + { 1269 + unsigned long flags; 1270 + enum sci_status status = SCI_SUCCESS; 1271 + int destroyed; 1272 + 1273 + spin_lock_irqsave(&ihost->scic_lock, flags); 1274 + /* Preserve any current resume callbacks, for instance from other 1275 + * resumptions. 1276 + */ 1277 + idev->abort_resume_cb = idev->rnc.user_callback; 1278 + idev->abort_resume_cbparam = idev->rnc.user_cookie; 1279 + set_bit(IDEV_ABORT_PATH_RESUME_PENDING, &idev->flags); 1280 + clear_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags); 1281 + destroyed = sci_remote_node_context_is_being_destroyed(&idev->rnc); 1282 + if (!destroyed) 1283 + status = sci_remote_device_resume( 1284 + idev, isci_remote_device_resume_from_abort_complete, 1285 + idev); 1286 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 1287 + if (!destroyed && (status == SCI_SUCCESS)) 1288 + isci_remote_device_wait_for_resume_from_abort(ihost, idev); 1289 + else 1290 + clear_bit(IDEV_ABORT_PATH_RESUME_PENDING, &idev->flags); 1291 + 1292 + return status; 1337 1293 } 1338 1294 1339 1295 /** ··· 1449 1207 * the device when there have been no phys added to it. 1450 1208 */ 1451 1209 static enum sci_status sci_remote_device_start(struct isci_remote_device *idev, 1452 - u32 timeout) 1210 + u32 timeout) 1453 1211 { 1454 1212 struct sci_base_state_machine *sm = &idev->sm; 1455 1213 enum sci_remote_device_states state = sm->current_state_id; ··· 1461 1219 return SCI_FAILURE_INVALID_STATE; 1462 1220 } 1463 1221 1464 - status = sci_remote_node_context_resume(&idev->rnc, 1465 - remote_device_resume_done, 1466 - idev); 1222 + status = sci_remote_device_resume(idev, remote_device_resume_done, 1223 + idev); 1467 1224 if (status != SCI_SUCCESS) 1468 1225 return status; 1469 1226 ··· 1500 1259 return status; 1501 1260 } 1502 1261 1503 - void isci_remote_device_nuke_requests(struct isci_host *ihost, struct isci_remote_device *idev) 1504 - { 1505 - DECLARE_COMPLETION_ONSTACK(aborted_task_completion); 1506 - 1507 - dev_dbg(&ihost->pdev->dev, 1508 - "%s: idev = %p\n", __func__, idev); 1509 - 1510 - /* Cleanup all requests pending for this device. */ 1511 - isci_terminate_pending_requests(ihost, idev); 1512 - 1513 - dev_dbg(&ihost->pdev->dev, 1514 - "%s: idev = %p, done\n", __func__, idev); 1515 - } 1516 - 1517 1262 /** 1518 1263 * This function builds the isci_remote_device when a libsas dev_found message 1519 1264 * is received. ··· 1524 1297 dev_warn(&ihost->pdev->dev, "%s: failed\n", __func__); 1525 1298 return NULL; 1526 1299 } 1527 - 1528 - if (WARN_ONCE(!list_empty(&idev->reqs_in_process), "found requests in process\n")) 1529 - return NULL; 1530 - 1531 1300 if (WARN_ONCE(!list_empty(&idev->node), "found non-idle remote device\n")) 1532 1301 return NULL; 1533 1302 ··· 1565 1342 spin_lock_irqsave(&ihost->scic_lock, flags); 1566 1343 idev->domain_dev->lldd_dev = NULL; /* disable new lookups */ 1567 1344 set_bit(IDEV_GONE, &idev->flags); 1568 - spin_unlock_irqrestore(&ihost->scic_lock, flags); 1569 - 1570 - /* Kill all outstanding requests. */ 1571 - isci_remote_device_nuke_requests(ihost, idev); 1572 1345 1573 1346 set_bit(IDEV_STOP_PENDING, &idev->flags); 1574 - 1575 - spin_lock_irqsave(&ihost->scic_lock, flags); 1576 1347 status = sci_remote_device_stop(idev, 50); 1577 1348 spin_unlock_irqrestore(&ihost->scic_lock, flags); 1578 1349 ··· 1575 1358 /* nothing to wait for */; 1576 1359 else 1577 1360 wait_for_device_stop(ihost, idev); 1361 + 1362 + dev_dbg(&ihost->pdev->dev, 1363 + "%s: isci_device = %p, waiting done.\n", __func__, idev); 1578 1364 1579 1365 return status; 1580 1366 } ··· 1653 1433 wait_for_device_start(isci_host, isci_device); 1654 1434 1655 1435 return status == SCI_SUCCESS ? 0 : -ENODEV; 1436 + } 1437 + 1438 + enum sci_status isci_remote_device_suspend_terminate( 1439 + struct isci_host *ihost, 1440 + struct isci_remote_device *idev, 1441 + struct isci_request *ireq) 1442 + { 1443 + unsigned long flags; 1444 + enum sci_status status; 1445 + 1446 + /* Put the device into suspension. */ 1447 + spin_lock_irqsave(&ihost->scic_lock, flags); 1448 + set_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags); 1449 + sci_remote_device_suspend(idev, SCI_SW_SUSPEND_LINKHANG_DETECT); 1450 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 1451 + 1452 + /* Terminate and wait for the completions. */ 1453 + status = isci_remote_device_terminate_requests(ihost, idev, ireq); 1454 + if (status != SCI_SUCCESS) 1455 + dev_dbg(&ihost->pdev->dev, 1456 + "%s: isci_remote_device_terminate_requests(%p) " 1457 + "returned %d!\n", 1458 + __func__, idev, status); 1459 + 1460 + /* NOTE: RNC resumption is left to the caller! */ 1461 + return status; 1462 + } 1463 + 1464 + int isci_remote_device_is_safe_to_abort( 1465 + struct isci_remote_device *idev) 1466 + { 1467 + return sci_remote_node_context_is_safe_to_abort(&idev->rnc); 1468 + } 1469 + 1470 + enum sci_status sci_remote_device_abort_requests_pending_abort( 1471 + struct isci_remote_device *idev) 1472 + { 1473 + return sci_remote_device_terminate_reqs_checkabort(idev, 1); 1474 + } 1475 + 1476 + enum sci_status isci_remote_device_reset_complete( 1477 + struct isci_host *ihost, 1478 + struct isci_remote_device *idev) 1479 + { 1480 + unsigned long flags; 1481 + enum sci_status status; 1482 + 1483 + spin_lock_irqsave(&ihost->scic_lock, flags); 1484 + status = sci_remote_device_reset_complete(idev); 1485 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 1486 + 1487 + return status; 1488 + } 1489 + 1490 + void isci_dev_set_hang_detection_timeout( 1491 + struct isci_remote_device *idev, 1492 + u32 timeout) 1493 + { 1494 + if (dev_is_sata(idev->domain_dev)) { 1495 + if (timeout) { 1496 + if (test_and_set_bit(IDEV_RNC_LLHANG_ENABLED, 1497 + &idev->flags)) 1498 + return; /* Already enabled. */ 1499 + } else if (!test_and_clear_bit(IDEV_RNC_LLHANG_ENABLED, 1500 + &idev->flags)) 1501 + return; /* Not enabled. */ 1502 + 1503 + sci_port_set_hang_detection_timeout(idev->owning_port, 1504 + timeout); 1505 + } 1656 1506 }
+57 -6
drivers/scsi/isci/remote_device.h
··· 85 85 #define IDEV_GONE 3 86 86 #define IDEV_IO_READY 4 87 87 #define IDEV_IO_NCQERROR 5 88 + #define IDEV_RNC_LLHANG_ENABLED 6 89 + #define IDEV_ABORT_PATH_ACTIVE 7 90 + #define IDEV_ABORT_PATH_RESUME_PENDING 8 88 91 unsigned long flags; 89 92 struct kref kref; 90 93 struct isci_port *isci_port; 91 94 struct domain_device *domain_dev; 92 95 struct list_head node; 93 - struct list_head reqs_in_process; 94 96 struct sci_base_state_machine sm; 95 97 u32 device_port_width; 96 98 enum sas_linkrate connection_rate; 97 - bool is_direct_attached; 98 99 struct isci_port *owning_port; 99 100 struct sci_remote_node_context rnc; 100 101 /* XXX unify with device reference counting and delete */ 101 102 u32 started_request_count; 102 103 struct isci_request *working_request; 103 104 u32 not_ready_reason; 105 + scics_sds_remote_node_context_callback abort_resume_cb; 106 + void *abort_resume_cbparam; 104 107 }; 105 108 106 109 #define ISCI_REMOTE_DEVICE_START_TIMEOUT 5000 107 110 108 111 /* device reference routines must be called under sci_lock */ 112 + static inline struct isci_remote_device *isci_get_device( 113 + struct isci_remote_device *idev) 114 + { 115 + if (idev) 116 + kref_get(&idev->kref); 117 + return idev; 118 + } 119 + 109 120 static inline struct isci_remote_device *isci_lookup_device(struct domain_device *dev) 110 121 { 111 122 struct isci_remote_device *idev = dev->lldd_dev; ··· 313 302 idev->started_request_count--; 314 303 } 315 304 305 + void isci_dev_set_hang_detection_timeout(struct isci_remote_device *idev, u32 timeout); 306 + 316 307 enum sci_status sci_remote_device_frame_handler( 317 308 struct isci_remote_device *idev, 318 309 u32 frame_index); ··· 338 325 struct isci_remote_device *idev, 339 326 struct isci_request *ireq); 340 327 341 - enum sci_status sci_remote_device_suspend( 342 - struct isci_remote_device *idev, 343 - u32 suspend_type); 344 - 345 328 void sci_remote_device_post_request( 346 329 struct isci_remote_device *idev, 347 330 u32 request); 348 331 332 + enum sci_status sci_remote_device_terminate_requests( 333 + struct isci_remote_device *idev); 334 + 335 + int isci_remote_device_is_safe_to_abort( 336 + struct isci_remote_device *idev); 337 + 338 + enum sci_status 339 + sci_remote_device_abort_requests_pending_abort( 340 + struct isci_remote_device *idev); 341 + 342 + enum sci_status isci_remote_device_suspend( 343 + struct isci_host *ihost, 344 + struct isci_remote_device *idev); 345 + 346 + enum sci_status sci_remote_device_resume( 347 + struct isci_remote_device *idev, 348 + scics_sds_remote_node_context_callback cb_fn, 349 + void *cb_p); 350 + 351 + enum sci_status isci_remote_device_resume_from_abort( 352 + struct isci_host *ihost, 353 + struct isci_remote_device *idev); 354 + 355 + enum sci_status isci_remote_device_reset( 356 + struct isci_host *ihost, 357 + struct isci_remote_device *idev); 358 + 359 + enum sci_status isci_remote_device_reset_complete( 360 + struct isci_host *ihost, 361 + struct isci_remote_device *idev); 362 + 363 + enum sci_status isci_remote_device_suspend_terminate( 364 + struct isci_host *ihost, 365 + struct isci_remote_device *idev, 366 + struct isci_request *ireq); 367 + 368 + enum sci_status isci_remote_device_terminate_requests( 369 + struct isci_host *ihost, 370 + struct isci_remote_device *idev, 371 + struct isci_request *ireq); 372 + enum sci_status sci_remote_device_suspend(struct isci_remote_device *idev, 373 + enum sci_remote_node_suspension_reasons reason); 349 374 #endif /* !defined(_ISCI_REMOTE_DEVICE_H_) */
+289 -104
drivers/scsi/isci/remote_node_context.c
··· 52 52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 53 53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 54 */ 55 - 55 + #include <scsi/sas_ata.h> 56 56 #include "host.h" 57 57 #include "isci.h" 58 58 #include "remote_device.h" ··· 87 87 return true; 88 88 } 89 89 90 + return false; 91 + } 92 + 93 + bool sci_remote_node_context_is_suspended(struct sci_remote_node_context *sci_rnc) 94 + { 95 + u32 current_state = sci_rnc->sm.current_state_id; 96 + 97 + if (current_state == SCI_RNC_TX_RX_SUSPENDED) 98 + return true; 90 99 return false; 91 100 } 92 101 ··· 140 131 141 132 rnc->ssp.arbitration_wait_time = 0; 142 133 143 - if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) { 134 + if (dev_is_sata(dev)) { 144 135 rnc->ssp.connection_occupancy_timeout = 145 136 ihost->user_parameters.stp_max_occupancy_timeout; 146 137 rnc->ssp.connection_inactivity_timeout = ··· 160 151 rnc->ssp.oaf_source_zone_group = 0; 161 152 rnc->ssp.oaf_more_compatibility_features = 0; 162 153 } 163 - 164 154 /** 165 155 * 166 156 * @sci_rnc: ··· 173 165 static void sci_remote_node_context_setup_to_resume( 174 166 struct sci_remote_node_context *sci_rnc, 175 167 scics_sds_remote_node_context_callback callback, 176 - void *callback_parameter) 168 + void *callback_parameter, 169 + enum sci_remote_node_context_destination_state dest_param) 177 170 { 178 - if (sci_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) { 179 - sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY; 180 - sci_rnc->user_callback = callback; 181 - sci_rnc->user_cookie = callback_parameter; 171 + if (sci_rnc->destination_state != RNC_DEST_FINAL) { 172 + sci_rnc->destination_state = dest_param; 173 + if (callback != NULL) { 174 + sci_rnc->user_callback = callback; 175 + sci_rnc->user_cookie = callback_parameter; 176 + } 182 177 } 183 178 } 184 179 185 - static void sci_remote_node_context_setup_to_destory( 180 + static void sci_remote_node_context_setup_to_destroy( 186 181 struct sci_remote_node_context *sci_rnc, 187 182 scics_sds_remote_node_context_callback callback, 188 183 void *callback_parameter) 189 184 { 190 - sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL; 185 + struct isci_host *ihost = idev_to_ihost(rnc_to_dev(sci_rnc)); 186 + 187 + sci_rnc->destination_state = RNC_DEST_FINAL; 191 188 sci_rnc->user_callback = callback; 192 189 sci_rnc->user_cookie = callback_parameter; 190 + 191 + wake_up(&ihost->eventq); 193 192 } 194 193 195 194 /** ··· 218 203 219 204 static void sci_remote_node_context_continue_state_transitions(struct sci_remote_node_context *rnc) 220 205 { 221 - if (rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) 206 + switch (rnc->destination_state) { 207 + case RNC_DEST_READY: 208 + case RNC_DEST_SUSPENDED_RESUME: 209 + rnc->destination_state = RNC_DEST_READY; 210 + /* Fall through... */ 211 + case RNC_DEST_FINAL: 222 212 sci_remote_node_context_resume(rnc, rnc->user_callback, 223 - rnc->user_cookie); 213 + rnc->user_cookie); 214 + break; 215 + default: 216 + rnc->destination_state = RNC_DEST_UNSPECIFIED; 217 + break; 218 + } 224 219 } 225 220 226 221 static void sci_remote_node_context_validate_context_buffer(struct sci_remote_node_context *sci_rnc) ··· 244 219 245 220 rnc_buffer->ssp.is_valid = true; 246 221 247 - if (!idev->is_direct_attached && 248 - (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))) { 222 + if (dev_is_sata(dev) && dev->parent) { 249 223 sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_96); 250 224 } else { 251 225 sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_32); 252 226 253 - if (idev->is_direct_attached) 227 + if (!dev->parent) 254 228 sci_port_setup_transports(idev->owning_port, 255 229 sci_rnc->remote_node_index); 256 230 } ··· 272 248 static void sci_remote_node_context_initial_state_enter(struct sci_base_state_machine *sm) 273 249 { 274 250 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); 251 + struct isci_remote_device *idev = rnc_to_dev(rnc); 252 + struct isci_host *ihost = idev->owning_port->owning_controller; 275 253 276 254 /* Check to see if we have gotten back to the initial state because 277 255 * someone requested to destroy the remote node context object. 278 256 */ 279 257 if (sm->previous_state_id == SCI_RNC_INVALIDATING) { 280 - rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED; 258 + rnc->destination_state = RNC_DEST_UNSPECIFIED; 281 259 sci_remote_node_context_notify_user(rnc); 260 + 261 + smp_wmb(); 262 + wake_up(&ihost->eventq); 282 263 } 283 264 } 284 265 ··· 298 269 { 299 270 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); 300 271 272 + /* Terminate all outstanding requests. */ 273 + sci_remote_device_terminate_requests(rnc_to_dev(rnc)); 301 274 sci_remote_node_context_invalidate_context_buffer(rnc); 302 275 } 303 276 ··· 318 287 * resume because of a target reset we also need to update 319 288 * the STPTLDARNI register with the RNi of the device 320 289 */ 321 - if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) && 322 - idev->is_direct_attached) 323 - sci_port_setup_transports(idev->owning_port, 324 - rnc->remote_node_index); 290 + if (dev_is_sata(dev) && !dev->parent) 291 + sci_port_setup_transports(idev->owning_port, rnc->remote_node_index); 325 292 326 293 sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME); 327 294 } ··· 327 298 static void sci_remote_node_context_ready_state_enter(struct sci_base_state_machine *sm) 328 299 { 329 300 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); 301 + enum sci_remote_node_context_destination_state dest_select; 302 + int tell_user = 1; 330 303 331 - rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED; 304 + dest_select = rnc->destination_state; 305 + rnc->destination_state = RNC_DEST_UNSPECIFIED; 332 306 333 - if (rnc->user_callback) 307 + if ((dest_select == RNC_DEST_SUSPENDED) || 308 + (dest_select == RNC_DEST_SUSPENDED_RESUME)) { 309 + sci_remote_node_context_suspend( 310 + rnc, rnc->suspend_reason, 311 + SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT); 312 + 313 + if (dest_select == RNC_DEST_SUSPENDED_RESUME) 314 + tell_user = 0; /* Wait until ready again. */ 315 + } 316 + if (tell_user) 334 317 sci_remote_node_context_notify_user(rnc); 335 318 } 336 319 ··· 356 315 static void sci_remote_node_context_tx_rx_suspended_state_enter(struct sci_base_state_machine *sm) 357 316 { 358 317 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); 318 + struct isci_remote_device *idev = rnc_to_dev(rnc); 319 + struct isci_host *ihost = idev->owning_port->owning_controller; 320 + u32 new_count = rnc->suspend_count + 1; 359 321 322 + if (new_count == 0) 323 + rnc->suspend_count = 1; 324 + else 325 + rnc->suspend_count = new_count; 326 + smp_wmb(); 327 + 328 + /* Terminate outstanding requests pending abort. */ 329 + sci_remote_device_abort_requests_pending_abort(idev); 330 + 331 + wake_up(&ihost->eventq); 360 332 sci_remote_node_context_continue_state_transitions(rnc); 333 + } 334 + 335 + static void sci_remote_node_context_await_suspend_state_exit( 336 + struct sci_base_state_machine *sm) 337 + { 338 + struct sci_remote_node_context *rnc 339 + = container_of(sm, typeof(*rnc), sm); 340 + struct isci_remote_device *idev = rnc_to_dev(rnc); 341 + 342 + if (dev_is_sata(idev->domain_dev)) 343 + isci_dev_set_hang_detection_timeout(idev, 0); 361 344 } 362 345 363 346 static const struct sci_base_state sci_remote_node_context_state_table[] = { ··· 406 341 [SCI_RNC_TX_RX_SUSPENDED] = { 407 342 .enter_state = sci_remote_node_context_tx_rx_suspended_state_enter, 408 343 }, 409 - [SCI_RNC_AWAIT_SUSPENSION] = { }, 344 + [SCI_RNC_AWAIT_SUSPENSION] = { 345 + .exit_state = sci_remote_node_context_await_suspend_state_exit, 346 + }, 410 347 }; 411 348 412 349 void sci_remote_node_context_construct(struct sci_remote_node_context *rnc, ··· 417 350 memset(rnc, 0, sizeof(struct sci_remote_node_context)); 418 351 419 352 rnc->remote_node_index = remote_node_index; 420 - rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED; 353 + rnc->destination_state = RNC_DEST_UNSPECIFIED; 421 354 422 355 sci_init_sm(&rnc->sm, sci_remote_node_context_state_table, SCI_RNC_INITIAL); 423 356 } ··· 426 359 u32 event_code) 427 360 { 428 361 enum scis_sds_remote_node_context_states state; 362 + u32 next_state; 429 363 430 364 state = sci_rnc->sm.current_state_id; 431 365 switch (state) { ··· 441 373 break; 442 374 case SCI_RNC_INVALIDATING: 443 375 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) { 444 - if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) 445 - state = SCI_RNC_INITIAL; 376 + if (sci_rnc->destination_state == RNC_DEST_FINAL) 377 + next_state = SCI_RNC_INITIAL; 446 378 else 447 - state = SCI_RNC_POSTING; 448 - sci_change_state(&sci_rnc->sm, state); 379 + next_state = SCI_RNC_POSTING; 380 + sci_change_state(&sci_rnc->sm, next_state); 449 381 } else { 450 382 switch (scu_get_event_type(event_code)) { 451 383 case SCU_EVENT_TYPE_RNC_SUSPEND_TX: 452 384 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: 453 385 /* We really dont care if the hardware is going to suspend 454 386 * the device since it's being invalidated anyway */ 455 - dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), 387 + dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 456 388 "%s: SCIC Remote Node Context 0x%p was " 457 389 "suspeneded by hardware while being " 458 390 "invalidated.\n", __func__, sci_rnc); ··· 471 403 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: 472 404 /* We really dont care if the hardware is going to suspend 473 405 * the device since it's being resumed anyway */ 474 - dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), 406 + dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 475 407 "%s: SCIC Remote Node Context 0x%p was " 476 408 "suspeneded by hardware while being resumed.\n", 477 409 __func__, sci_rnc); ··· 485 417 switch (scu_get_event_type(event_code)) { 486 418 case SCU_EVENT_TL_RNC_SUSPEND_TX: 487 419 sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED); 488 - sci_rnc->suspension_code = scu_get_event_specifier(event_code); 420 + sci_rnc->suspend_type = scu_get_event_type(event_code); 489 421 break; 490 422 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX: 491 423 sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED); 492 - sci_rnc->suspension_code = scu_get_event_specifier(event_code); 424 + sci_rnc->suspend_type = scu_get_event_type(event_code); 493 425 break; 494 426 default: 495 427 goto out; ··· 498 430 case SCI_RNC_AWAIT_SUSPENSION: 499 431 switch (scu_get_event_type(event_code)) { 500 432 case SCU_EVENT_TL_RNC_SUSPEND_TX: 501 - sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED); 502 - sci_rnc->suspension_code = scu_get_event_specifier(event_code); 433 + next_state = SCI_RNC_TX_SUSPENDED; 503 434 break; 504 435 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX: 505 - sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED); 506 - sci_rnc->suspension_code = scu_get_event_specifier(event_code); 436 + next_state = SCI_RNC_TX_RX_SUSPENDED; 507 437 break; 508 438 default: 509 439 goto out; 510 440 } 441 + if (sci_rnc->suspend_type == scu_get_event_type(event_code)) 442 + sci_change_state(&sci_rnc->sm, next_state); 511 443 break; 512 444 default: 513 445 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 514 - "%s: invalid state %d\n", __func__, state); 446 + "%s: invalid state: %s\n", __func__, 447 + rnc_state_name(state)); 515 448 return SCI_FAILURE_INVALID_STATE; 516 449 } 517 450 return SCI_SUCCESS; 518 451 519 452 out: 520 453 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 521 - "%s: code: %#x state: %d\n", __func__, event_code, state); 454 + "%s: code: %#x state: %s\n", __func__, event_code, 455 + rnc_state_name(state)); 522 456 return SCI_FAILURE; 523 457 524 458 } ··· 534 464 state = sci_rnc->sm.current_state_id; 535 465 switch (state) { 536 466 case SCI_RNC_INVALIDATING: 537 - sci_remote_node_context_setup_to_destory(sci_rnc, cb_fn, cb_p); 467 + sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p); 538 468 return SCI_SUCCESS; 539 469 case SCI_RNC_POSTING: 540 470 case SCI_RNC_RESUMING: 541 471 case SCI_RNC_READY: 542 472 case SCI_RNC_TX_SUSPENDED: 543 473 case SCI_RNC_TX_RX_SUSPENDED: 544 - case SCI_RNC_AWAIT_SUSPENSION: 545 - sci_remote_node_context_setup_to_destory(sci_rnc, cb_fn, cb_p); 474 + sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p); 546 475 sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING); 476 + return SCI_SUCCESS; 477 + case SCI_RNC_AWAIT_SUSPENSION: 478 + sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p); 547 479 return SCI_SUCCESS; 548 480 case SCI_RNC_INITIAL: 549 481 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 550 - "%s: invalid state %d\n", __func__, state); 482 + "%s: invalid state: %s\n", __func__, 483 + rnc_state_name(state)); 551 484 /* We have decided that the destruct request on the remote node context 552 485 * can not fail since it is either in the initial/destroyed state or is 553 486 * can be destroyed. ··· 558 485 return SCI_SUCCESS; 559 486 default: 560 487 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 561 - "%s: invalid state %d\n", __func__, state); 488 + "%s: invalid state %s\n", __func__, 489 + rnc_state_name(state)); 562 490 return SCI_FAILURE_INVALID_STATE; 563 491 } 564 492 } 565 493 566 - enum sci_status sci_remote_node_context_suspend(struct sci_remote_node_context *sci_rnc, 567 - u32 suspend_type, 568 - scics_sds_remote_node_context_callback cb_fn, 569 - void *cb_p) 494 + enum sci_status sci_remote_node_context_suspend( 495 + struct sci_remote_node_context *sci_rnc, 496 + enum sci_remote_node_suspension_reasons suspend_reason, 497 + u32 suspend_type) 570 498 { 571 - enum scis_sds_remote_node_context_states state; 499 + enum scis_sds_remote_node_context_states state 500 + = sci_rnc->sm.current_state_id; 501 + struct isci_remote_device *idev = rnc_to_dev(sci_rnc); 502 + enum sci_status status = SCI_FAILURE_INVALID_STATE; 503 + enum sci_remote_node_context_destination_state dest_param = 504 + RNC_DEST_UNSPECIFIED; 572 505 573 - state = sci_rnc->sm.current_state_id; 574 - if (state != SCI_RNC_READY) { 506 + dev_dbg(scirdev_to_dev(idev), 507 + "%s: current state %s, current suspend_type %x dest state %d," 508 + " arg suspend_reason %d, arg suspend_type %x", 509 + __func__, rnc_state_name(state), sci_rnc->suspend_type, 510 + sci_rnc->destination_state, suspend_reason, 511 + suspend_type); 512 + 513 + /* Disable automatic state continuations if explicitly suspending. */ 514 + if ((suspend_reason == SCI_HW_SUSPEND) || 515 + (sci_rnc->destination_state == RNC_DEST_FINAL)) 516 + dest_param = sci_rnc->destination_state; 517 + 518 + switch (state) { 519 + case SCI_RNC_READY: 520 + break; 521 + case SCI_RNC_INVALIDATING: 522 + if (sci_rnc->destination_state == RNC_DEST_FINAL) { 523 + dev_warn(scirdev_to_dev(idev), 524 + "%s: already destroying %p\n", 525 + __func__, sci_rnc); 526 + return SCI_FAILURE_INVALID_STATE; 527 + } 528 + /* Fall through and handle like SCI_RNC_POSTING */ 529 + case SCI_RNC_RESUMING: 530 + /* Fall through and handle like SCI_RNC_POSTING */ 531 + case SCI_RNC_POSTING: 532 + /* Set the destination state to AWAIT - this signals the 533 + * entry into the SCI_RNC_READY state that a suspension 534 + * needs to be done immediately. 535 + */ 536 + if (sci_rnc->destination_state != RNC_DEST_FINAL) 537 + sci_rnc->destination_state = RNC_DEST_SUSPENDED; 538 + sci_rnc->suspend_type = suspend_type; 539 + sci_rnc->suspend_reason = suspend_reason; 540 + return SCI_SUCCESS; 541 + 542 + case SCI_RNC_TX_SUSPENDED: 543 + if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX) 544 + status = SCI_SUCCESS; 545 + break; 546 + case SCI_RNC_TX_RX_SUSPENDED: 547 + if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX) 548 + status = SCI_SUCCESS; 549 + break; 550 + case SCI_RNC_AWAIT_SUSPENSION: 551 + if ((sci_rnc->suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX) 552 + || (suspend_type == sci_rnc->suspend_type)) 553 + return SCI_SUCCESS; 554 + break; 555 + default: 575 556 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 576 - "%s: invalid state %d\n", __func__, state); 557 + "%s: invalid state %s\n", __func__, 558 + rnc_state_name(state)); 577 559 return SCI_FAILURE_INVALID_STATE; 578 560 } 561 + sci_rnc->destination_state = dest_param; 562 + sci_rnc->suspend_type = suspend_type; 563 + sci_rnc->suspend_reason = suspend_reason; 579 564 580 - sci_rnc->user_callback = cb_fn; 581 - sci_rnc->user_cookie = cb_p; 582 - sci_rnc->suspension_code = suspend_type; 565 + if (status == SCI_SUCCESS) { /* Already in the destination state? */ 566 + struct isci_host *ihost = idev->owning_port->owning_controller; 583 567 584 - if (suspend_type == SCI_SOFTWARE_SUSPENSION) { 585 - sci_remote_device_post_request(rnc_to_dev(sci_rnc), 586 - SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX); 568 + wake_up_all(&ihost->eventq); /* Let observers look. */ 569 + return SCI_SUCCESS; 587 570 } 571 + if ((suspend_reason == SCI_SW_SUSPEND_NORMAL) || 572 + (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT)) { 588 573 589 - sci_change_state(&sci_rnc->sm, SCI_RNC_AWAIT_SUSPENSION); 574 + if (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT) 575 + isci_dev_set_hang_detection_timeout(idev, 0x00000001); 576 + 577 + sci_remote_device_post_request( 578 + idev, SCI_SOFTWARE_SUSPEND_CMD); 579 + } 580 + if (state != SCI_RNC_AWAIT_SUSPENSION) 581 + sci_change_state(&sci_rnc->sm, SCI_RNC_AWAIT_SUSPENSION); 582 + 590 583 return SCI_SUCCESS; 591 584 } 592 585 ··· 661 522 void *cb_p) 662 523 { 663 524 enum scis_sds_remote_node_context_states state; 525 + struct isci_remote_device *idev = rnc_to_dev(sci_rnc); 664 526 665 527 state = sci_rnc->sm.current_state_id; 528 + dev_dbg(scirdev_to_dev(idev), 529 + "%s: state %s, cb_fn = %p, cb_p = %p; dest_state = %d; " 530 + "dev resume path %s\n", 531 + __func__, rnc_state_name(state), cb_fn, cb_p, 532 + sci_rnc->destination_state, 533 + test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags) 534 + ? "<abort active>" : "<normal>"); 535 + 666 536 switch (state) { 667 537 case SCI_RNC_INITIAL: 668 538 if (sci_rnc->remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) 669 539 return SCI_FAILURE_INVALID_STATE; 670 540 671 - sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p); 672 - sci_remote_node_context_construct_buffer(sci_rnc); 673 - sci_change_state(&sci_rnc->sm, SCI_RNC_POSTING); 541 + sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p, 542 + RNC_DEST_READY); 543 + if (!test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)) { 544 + sci_remote_node_context_construct_buffer(sci_rnc); 545 + sci_change_state(&sci_rnc->sm, SCI_RNC_POSTING); 546 + } 674 547 return SCI_SUCCESS; 548 + 675 549 case SCI_RNC_POSTING: 676 550 case SCI_RNC_INVALIDATING: 677 551 case SCI_RNC_RESUMING: 678 - if (sci_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) 679 - return SCI_FAILURE_INVALID_STATE; 680 - 681 - sci_rnc->user_callback = cb_fn; 682 - sci_rnc->user_cookie = cb_p; 552 + /* We are still waiting to post when a resume was 553 + * requested. 554 + */ 555 + switch (sci_rnc->destination_state) { 556 + case RNC_DEST_SUSPENDED: 557 + case RNC_DEST_SUSPENDED_RESUME: 558 + /* Previously waiting to suspend after posting. 559 + * Now continue onto resumption. 560 + */ 561 + sci_remote_node_context_setup_to_resume( 562 + sci_rnc, cb_fn, cb_p, 563 + RNC_DEST_SUSPENDED_RESUME); 564 + break; 565 + default: 566 + sci_remote_node_context_setup_to_resume( 567 + sci_rnc, cb_fn, cb_p, 568 + RNC_DEST_READY); 569 + break; 570 + } 683 571 return SCI_SUCCESS; 684 - case SCI_RNC_TX_SUSPENDED: { 685 - struct isci_remote_device *idev = rnc_to_dev(sci_rnc); 686 - struct domain_device *dev = idev->domain_dev; 687 572 688 - sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p); 689 - 690 - /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */ 691 - if (dev->dev_type == SAS_END_DEV || dev_is_expander(dev)) 692 - sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING); 693 - else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) { 694 - if (idev->is_direct_attached) { 695 - /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */ 696 - sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING); 697 - } else { 698 - sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING); 699 - } 700 - } else 701 - return SCI_FAILURE; 702 - return SCI_SUCCESS; 703 - } 573 + case SCI_RNC_TX_SUSPENDED: 704 574 case SCI_RNC_TX_RX_SUSPENDED: 705 - sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p); 706 - sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING); 707 - return SCI_FAILURE_INVALID_STATE; 575 + { 576 + struct domain_device *dev = idev->domain_dev; 577 + /* If this is an expander attached SATA device we must 578 + * invalidate and repost the RNC since this is the only 579 + * way to clear the TCi to NCQ tag mapping table for 580 + * the RNi. All other device types we can just resume. 581 + */ 582 + sci_remote_node_context_setup_to_resume( 583 + sci_rnc, cb_fn, cb_p, RNC_DEST_READY); 584 + 585 + if (!test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)) { 586 + if ((dev_is_sata(dev) && dev->parent) || 587 + (sci_rnc->destination_state == RNC_DEST_FINAL)) 588 + sci_change_state(&sci_rnc->sm, 589 + SCI_RNC_INVALIDATING); 590 + else 591 + sci_change_state(&sci_rnc->sm, 592 + SCI_RNC_RESUMING); 593 + } 594 + } 595 + return SCI_SUCCESS; 596 + 708 597 case SCI_RNC_AWAIT_SUSPENSION: 709 - sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p); 598 + sci_remote_node_context_setup_to_resume( 599 + sci_rnc, cb_fn, cb_p, RNC_DEST_SUSPENDED_RESUME); 710 600 return SCI_SUCCESS; 711 601 default: 712 602 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 713 - "%s: invalid state %d\n", __func__, state); 603 + "%s: invalid state %s\n", __func__, 604 + rnc_state_name(state)); 714 605 return SCI_FAILURE_INVALID_STATE; 715 606 } 716 607 } ··· 759 590 case SCI_RNC_TX_RX_SUSPENDED: 760 591 case SCI_RNC_AWAIT_SUSPENSION: 761 592 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 762 - "%s: invalid state %d\n", __func__, state); 593 + "%s: invalid state %s\n", __func__, 594 + rnc_state_name(state)); 763 595 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; 764 596 default: 765 - break; 597 + dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), 598 + "%s: invalid state %s\n", __func__, 599 + rnc_state_name(state)); 600 + return SCI_FAILURE_INVALID_STATE; 766 601 } 767 - dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), 768 - "%s: requested to start IO while still resuming, %d\n", 769 - __func__, state); 770 - return SCI_FAILURE_INVALID_STATE; 771 602 } 772 603 773 - enum sci_status sci_remote_node_context_start_task(struct sci_remote_node_context *sci_rnc, 774 - struct isci_request *ireq) 604 + enum sci_status sci_remote_node_context_start_task( 605 + struct sci_remote_node_context *sci_rnc, 606 + struct isci_request *ireq, 607 + scics_sds_remote_node_context_callback cb_fn, 608 + void *cb_p) 609 + { 610 + enum sci_status status = sci_remote_node_context_resume(sci_rnc, 611 + cb_fn, cb_p); 612 + if (status != SCI_SUCCESS) 613 + dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 614 + "%s: resume failed: %d\n", __func__, status); 615 + return status; 616 + } 617 + 618 + int sci_remote_node_context_is_safe_to_abort( 619 + struct sci_remote_node_context *sci_rnc) 775 620 { 776 621 enum scis_sds_remote_node_context_states state; 777 622 778 623 state = sci_rnc->sm.current_state_id; 779 624 switch (state) { 625 + case SCI_RNC_INVALIDATING: 626 + case SCI_RNC_TX_RX_SUSPENDED: 627 + return 1; 628 + case SCI_RNC_POSTING: 780 629 case SCI_RNC_RESUMING: 781 630 case SCI_RNC_READY: 782 - case SCI_RNC_AWAIT_SUSPENSION: 783 - return SCI_SUCCESS; 784 631 case SCI_RNC_TX_SUSPENDED: 785 - case SCI_RNC_TX_RX_SUSPENDED: 786 - sci_remote_node_context_resume(sci_rnc, NULL, NULL); 787 - return SCI_SUCCESS; 632 + case SCI_RNC_AWAIT_SUSPENSION: 633 + case SCI_RNC_INITIAL: 634 + return 0; 788 635 default: 789 636 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), 790 637 "%s: invalid state %d\n", __func__, state); 791 - return SCI_FAILURE_INVALID_STATE; 638 + return 0; 792 639 } 793 640 }
+33 -10
drivers/scsi/isci/remote_node_context.h
··· 75 75 */ 76 76 #define SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX 0x0FFF 77 77 78 - #define SCU_HARDWARE_SUSPENSION (0) 79 - #define SCI_SOFTWARE_SUSPENSION (1) 78 + enum sci_remote_node_suspension_reasons { 79 + SCI_HW_SUSPEND, 80 + SCI_SW_SUSPEND_NORMAL, 81 + SCI_SW_SUSPEND_LINKHANG_DETECT 82 + }; 83 + #define SCI_SOFTWARE_SUSPEND_CMD SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX 84 + #define SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT SCU_EVENT_TL_RNC_SUSPEND_TX_RX 80 85 81 86 struct isci_request; 82 87 struct isci_remote_device; ··· 142 137 * node context. 143 138 */ 144 139 enum sci_remote_node_context_destination_state { 145 - SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED, 146 - SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY, 147 - SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL 140 + RNC_DEST_UNSPECIFIED, 141 + RNC_DEST_READY, 142 + RNC_DEST_FINAL, 143 + RNC_DEST_SUSPENDED, /* Set when suspend during post/invalidate */ 144 + RNC_DEST_SUSPENDED_RESUME /* Set when a resume was done during posting 145 + * or invalidating and already suspending. 146 + */ 148 147 }; 149 148 150 149 /** ··· 165 156 u16 remote_node_index; 166 157 167 158 /** 168 - * This field is the recored suspension code or the reason for the remote node 159 + * This field is the recored suspension type of the remote node 169 160 * context suspension. 170 161 */ 171 - u32 suspension_code; 162 + u32 suspend_type; 163 + enum sci_remote_node_suspension_reasons suspend_reason; 164 + u32 suspend_count; 172 165 173 166 /** 174 167 * This field is true if the remote node context is resuming from its current ··· 204 193 bool sci_remote_node_context_is_ready( 205 194 struct sci_remote_node_context *sci_rnc); 206 195 196 + bool sci_remote_node_context_is_suspended(struct sci_remote_node_context *sci_rnc); 197 + 207 198 enum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc, 208 199 u32 event_code); 209 200 enum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc, ··· 213 200 void *callback_parameter); 214 201 enum sci_status sci_remote_node_context_suspend(struct sci_remote_node_context *sci_rnc, 215 202 u32 suspend_type, 216 - scics_sds_remote_node_context_callback cb_fn, 217 - void *cb_p); 203 + u32 suspension_code); 218 204 enum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc, 219 205 scics_sds_remote_node_context_callback cb_fn, 220 206 void *cb_p); 221 207 enum sci_status sci_remote_node_context_start_task(struct sci_remote_node_context *sci_rnc, 222 - struct isci_request *ireq); 208 + struct isci_request *ireq, 209 + scics_sds_remote_node_context_callback cb_fn, 210 + void *cb_p); 223 211 enum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc, 224 212 struct isci_request *ireq); 213 + int sci_remote_node_context_is_safe_to_abort( 214 + struct sci_remote_node_context *sci_rnc); 225 215 216 + static inline bool sci_remote_node_context_is_being_destroyed( 217 + struct sci_remote_node_context *sci_rnc) 218 + { 219 + return (sci_rnc->destination_state == RNC_DEST_FINAL) 220 + || ((sci_rnc->sm.current_state_id == SCI_RNC_INITIAL) 221 + && (sci_rnc->destination_state == RNC_DEST_UNSPECIFIED)); 222 + } 226 223 #endif /* _SCIC_SDS_REMOTE_NODE_CONTEXT_H_ */
+325 -424
drivers/scsi/isci/request.c
··· 92 92 if (idx == 0) { 93 93 offset = (void *) &ireq->tc->sgl_pair_ab - 94 94 (void *) &ihost->task_context_table[0]; 95 - return ihost->task_context_dma + offset; 95 + return ihost->tc_dma + offset; 96 96 } else if (idx == 1) { 97 97 offset = (void *) &ireq->tc->sgl_pair_cd - 98 98 (void *) &ihost->task_context_table[0]; 99 - return ihost->task_context_dma + offset; 99 + return ihost->tc_dma + offset; 100 100 } 101 101 102 102 return sci_io_request_get_dma_addr(ireq, &ireq->sg_table[idx - 2]); ··· 730 730 { 731 731 struct sas_task *task = isci_request_access_task(ireq); 732 732 733 - ireq->protocol = SCIC_SSP_PROTOCOL; 733 + ireq->protocol = SAS_PROTOCOL_SSP; 734 734 735 735 scu_ssp_io_request_construct_task_context(ireq, 736 736 task->data_dir, ··· 763 763 bool copy = false; 764 764 struct sas_task *task = isci_request_access_task(ireq); 765 765 766 - ireq->protocol = SCIC_STP_PROTOCOL; 766 + ireq->protocol = SAS_PROTOCOL_STP; 767 767 768 768 copy = (task->data_dir == DMA_NONE) ? false : true; 769 769 ··· 863 863 864 864 switch (state) { 865 865 case SCI_REQ_CONSTRUCTED: 866 + /* Set to make sure no HW terminate posting is done: */ 867 + set_bit(IREQ_TC_ABORT_POSTED, &ireq->flags); 866 868 ireq->scu_status = SCU_TASK_DONE_TASK_ABORT; 867 869 ireq->sci_status = SCI_FAILURE_IO_TERMINATED; 868 870 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); ··· 885 883 case SCI_REQ_ATAPI_WAIT_PIO_SETUP: 886 884 case SCI_REQ_ATAPI_WAIT_D2H: 887 885 case SCI_REQ_ATAPI_WAIT_TC_COMP: 888 - sci_change_state(&ireq->sm, SCI_REQ_ABORTING); 889 - return SCI_SUCCESS; 886 + /* Fall through and change state to ABORTING... */ 890 887 case SCI_REQ_TASK_WAIT_TC_RESP: 891 888 /* The task frame was already confirmed to have been 892 889 * sent by the SCU HW. Since the state machine is ··· 894 893 * and don't wait for the task response. 895 894 */ 896 895 sci_change_state(&ireq->sm, SCI_REQ_ABORTING); 897 - sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); 898 - return SCI_SUCCESS; 896 + /* Fall through and handle like ABORTING... */ 899 897 case SCI_REQ_ABORTING: 900 - /* If a request has a termination requested twice, return 901 - * a failure indication, since HW confirmation of the first 902 - * abort is still outstanding. 898 + if (!isci_remote_device_is_safe_to_abort(ireq->target_device)) 899 + set_bit(IREQ_PENDING_ABORT, &ireq->flags); 900 + else 901 + clear_bit(IREQ_PENDING_ABORT, &ireq->flags); 902 + /* If the request is only waiting on the remote device 903 + * suspension, return SUCCESS so the caller will wait too. 903 904 */ 905 + return SCI_SUCCESS; 904 906 case SCI_REQ_COMPLETED: 905 907 default: 906 908 dev_warn(&ireq->owning_controller->pdev->dev, 907 909 "%s: SCIC IO Request requested to abort while in wrong " 908 - "state %d\n", 909 - __func__, 910 - ireq->sm.current_state_id); 910 + "state %d\n", __func__, ireq->sm.current_state_id); 911 911 break; 912 912 } 913 913 ··· 1072 1070 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS): 1073 1071 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR): 1074 1072 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR): 1075 - if (ireq->protocol == SCIC_STP_PROTOCOL) { 1073 + if (ireq->protocol == SAS_PROTOCOL_STP) { 1076 1074 ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> 1077 1075 SCU_COMPLETION_TL_STATUS_SHIFT; 1078 1076 ireq->sci_status = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; ··· 2119 2117 */ 2120 2118 if (ireq->stp.rsp.fis_type == FIS_REGD2H) { 2121 2119 sci_remote_device_suspend(ireq->target_device, 2122 - SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code))); 2120 + SCI_SW_SUSPEND_NORMAL); 2123 2121 2124 2122 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; 2125 2123 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; ··· 2140 2138 /* TODO We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR 2141 2139 * - this comes only for B0 2142 2140 */ 2143 - case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN): 2144 - case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR): 2145 - case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR): 2146 - case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR): 2147 - sci_remote_device_suspend(ireq->target_device, 2148 - SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code))); 2149 - /* Fall through to the default case */ 2150 2141 default: 2151 2142 /* All other completion status cause the IO to be complete. */ 2152 2143 ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); ··· 2257 2262 return status; 2258 2263 } 2259 2264 2265 + static int sci_request_smp_completion_status_is_tx_suspend( 2266 + unsigned int completion_status) 2267 + { 2268 + switch (completion_status) { 2269 + case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: 2270 + case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: 2271 + case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: 2272 + case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: 2273 + case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: 2274 + case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: 2275 + return 1; 2276 + } 2277 + return 0; 2278 + } 2279 + 2280 + static int sci_request_smp_completion_status_is_tx_rx_suspend( 2281 + unsigned int completion_status) 2282 + { 2283 + return 0; /* There are no Tx/Rx SMP suspend conditions. */ 2284 + } 2285 + 2286 + static int sci_request_ssp_completion_status_is_tx_suspend( 2287 + unsigned int completion_status) 2288 + { 2289 + switch (completion_status) { 2290 + case SCU_TASK_DONE_TX_RAW_CMD_ERR: 2291 + case SCU_TASK_DONE_LF_ERR: 2292 + case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: 2293 + case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: 2294 + case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: 2295 + case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: 2296 + case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: 2297 + case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: 2298 + case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: 2299 + case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: 2300 + case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: 2301 + return 1; 2302 + } 2303 + return 0; 2304 + } 2305 + 2306 + static int sci_request_ssp_completion_status_is_tx_rx_suspend( 2307 + unsigned int completion_status) 2308 + { 2309 + return 0; /* There are no Tx/Rx SSP suspend conditions. */ 2310 + } 2311 + 2312 + static int sci_request_stpsata_completion_status_is_tx_suspend( 2313 + unsigned int completion_status) 2314 + { 2315 + switch (completion_status) { 2316 + case SCU_TASK_DONE_TX_RAW_CMD_ERR: 2317 + case SCU_TASK_DONE_LL_R_ERR: 2318 + case SCU_TASK_DONE_LL_PERR: 2319 + case SCU_TASK_DONE_REG_ERR: 2320 + case SCU_TASK_DONE_SDB_ERR: 2321 + case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: 2322 + case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: 2323 + case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: 2324 + case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: 2325 + case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: 2326 + case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: 2327 + case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: 2328 + case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: 2329 + case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: 2330 + return 1; 2331 + } 2332 + return 0; 2333 + } 2334 + 2335 + 2336 + static int sci_request_stpsata_completion_status_is_tx_rx_suspend( 2337 + unsigned int completion_status) 2338 + { 2339 + switch (completion_status) { 2340 + case SCU_TASK_DONE_LF_ERR: 2341 + case SCU_TASK_DONE_LL_SY_TERM: 2342 + case SCU_TASK_DONE_LL_LF_TERM: 2343 + case SCU_TASK_DONE_BREAK_RCVD: 2344 + case SCU_TASK_DONE_INV_FIS_LEN: 2345 + case SCU_TASK_DONE_UNEXP_FIS: 2346 + case SCU_TASK_DONE_UNEXP_SDBFIS: 2347 + case SCU_TASK_DONE_MAX_PLD_ERR: 2348 + return 1; 2349 + } 2350 + return 0; 2351 + } 2352 + 2353 + static void sci_request_handle_suspending_completions( 2354 + struct isci_request *ireq, 2355 + u32 completion_code) 2356 + { 2357 + int is_tx = 0; 2358 + int is_tx_rx = 0; 2359 + 2360 + switch (ireq->protocol) { 2361 + case SAS_PROTOCOL_SMP: 2362 + is_tx = sci_request_smp_completion_status_is_tx_suspend( 2363 + completion_code); 2364 + is_tx_rx = sci_request_smp_completion_status_is_tx_rx_suspend( 2365 + completion_code); 2366 + break; 2367 + case SAS_PROTOCOL_SSP: 2368 + is_tx = sci_request_ssp_completion_status_is_tx_suspend( 2369 + completion_code); 2370 + is_tx_rx = sci_request_ssp_completion_status_is_tx_rx_suspend( 2371 + completion_code); 2372 + break; 2373 + case SAS_PROTOCOL_STP: 2374 + is_tx = sci_request_stpsata_completion_status_is_tx_suspend( 2375 + completion_code); 2376 + is_tx_rx = 2377 + sci_request_stpsata_completion_status_is_tx_rx_suspend( 2378 + completion_code); 2379 + break; 2380 + default: 2381 + dev_warn(&ireq->isci_host->pdev->dev, 2382 + "%s: request %p has no valid protocol\n", 2383 + __func__, ireq); 2384 + break; 2385 + } 2386 + if (is_tx || is_tx_rx) { 2387 + BUG_ON(is_tx && is_tx_rx); 2388 + 2389 + sci_remote_node_context_suspend( 2390 + &ireq->target_device->rnc, 2391 + SCI_HW_SUSPEND, 2392 + (is_tx_rx) ? SCU_EVENT_TL_RNC_SUSPEND_TX_RX 2393 + : SCU_EVENT_TL_RNC_SUSPEND_TX); 2394 + } 2395 + } 2396 + 2260 2397 enum sci_status 2261 2398 sci_io_request_tc_completion(struct isci_request *ireq, 2262 - u32 completion_code) 2399 + u32 completion_code) 2263 2400 { 2264 2401 enum sci_base_request_states state; 2265 2402 struct isci_host *ihost = ireq->owning_controller; 2266 2403 2267 2404 state = ireq->sm.current_state_id; 2405 + 2406 + /* Decode those completions that signal upcoming suspension events. */ 2407 + sci_request_handle_suspending_completions( 2408 + ireq, SCU_GET_COMPLETION_TL_STATUS(completion_code)); 2268 2409 2269 2410 switch (state) { 2270 2411 case SCI_REQ_STARTED: ··· 2493 2362 * @request: This parameter is the completed isci_request object. 2494 2363 * @response_ptr: This parameter specifies the service response for the I/O. 2495 2364 * @status_ptr: This parameter specifies the exec status for the I/O. 2496 - * @complete_to_host_ptr: This parameter specifies the action to be taken by 2497 - * the LLDD with respect to completing this request or forcing an abort 2498 - * condition on the I/O. 2499 2365 * @open_rej_reason: This parameter specifies the encoded reason for the 2500 2366 * abandon-class reject. 2501 2367 * ··· 2503 2375 struct sas_task *task, 2504 2376 enum service_response *response_ptr, 2505 2377 enum exec_status *status_ptr, 2506 - enum isci_completion_selection *complete_to_host_ptr, 2507 2378 enum sas_open_rej_reason open_rej_reason) 2508 2379 { 2509 2380 /* Task in the target is done. */ 2510 2381 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2511 2382 *response_ptr = SAS_TASK_UNDELIVERED; 2512 2383 *status_ptr = SAS_OPEN_REJECT; 2513 - *complete_to_host_ptr = isci_perform_normal_io_completion; 2514 2384 task->task_status.open_rej_reason = open_rej_reason; 2515 2385 } 2516 2386 ··· 2518 2392 * @request: This parameter is the completed isci_request object. 2519 2393 * @response_ptr: This parameter specifies the service response for the I/O. 2520 2394 * @status_ptr: This parameter specifies the exec status for the I/O. 2521 - * @complete_to_host_ptr: This parameter specifies the action to be taken by 2522 - * the LLDD with respect to completing this request or forcing an abort 2523 - * condition on the I/O. 2524 2395 * 2525 2396 * none. 2526 2397 */ ··· 2526 2403 struct isci_request *request, 2527 2404 struct sas_task *task, 2528 2405 enum service_response *response_ptr, 2529 - enum exec_status *status_ptr, 2530 - enum isci_completion_selection *complete_to_host_ptr) 2406 + enum exec_status *status_ptr) 2531 2407 { 2532 2408 unsigned int cstatus; 2533 2409 ··· 2567 2445 *status_ptr = SAS_ABORTED_TASK; 2568 2446 2569 2447 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2570 - 2571 - *complete_to_host_ptr = 2572 - isci_perform_normal_io_completion; 2573 2448 } else { 2574 2449 /* Task in the target is not done. */ 2575 2450 *response_ptr = SAS_TASK_UNDELIVERED; ··· 2577 2458 *status_ptr = SAM_STAT_TASK_ABORTED; 2578 2459 2579 2460 clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2580 - 2581 - *complete_to_host_ptr = 2582 - isci_perform_error_io_completion; 2583 2461 } 2584 2462 2585 2463 break; ··· 2605 2489 *status_ptr = SAS_ABORTED_TASK; 2606 2490 2607 2491 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2608 - 2609 - *complete_to_host_ptr = isci_perform_normal_io_completion; 2610 2492 break; 2611 2493 2612 2494 ··· 2615 2501 2616 2502 isci_request_set_open_reject_status( 2617 2503 request, task, response_ptr, status_ptr, 2618 - complete_to_host_ptr, SAS_OREJ_WRONG_DEST); 2504 + SAS_OREJ_WRONG_DEST); 2619 2505 break; 2620 2506 2621 2507 case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: ··· 2625 2511 */ 2626 2512 isci_request_set_open_reject_status( 2627 2513 request, task, response_ptr, status_ptr, 2628 - complete_to_host_ptr, SAS_OREJ_RESV_AB0); 2514 + SAS_OREJ_RESV_AB0); 2629 2515 break; 2630 2516 2631 2517 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: 2632 2518 2633 2519 isci_request_set_open_reject_status( 2634 2520 request, task, response_ptr, status_ptr, 2635 - complete_to_host_ptr, SAS_OREJ_RESV_AB1); 2521 + SAS_OREJ_RESV_AB1); 2636 2522 break; 2637 2523 2638 2524 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: 2639 2525 2640 2526 isci_request_set_open_reject_status( 2641 2527 request, task, response_ptr, status_ptr, 2642 - complete_to_host_ptr, SAS_OREJ_RESV_AB2); 2528 + SAS_OREJ_RESV_AB2); 2643 2529 break; 2644 2530 2645 2531 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: 2646 2532 2647 2533 isci_request_set_open_reject_status( 2648 2534 request, task, response_ptr, status_ptr, 2649 - complete_to_host_ptr, SAS_OREJ_RESV_AB3); 2535 + SAS_OREJ_RESV_AB3); 2650 2536 break; 2651 2537 2652 2538 case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: 2653 2539 2654 2540 isci_request_set_open_reject_status( 2655 2541 request, task, response_ptr, status_ptr, 2656 - complete_to_host_ptr, SAS_OREJ_BAD_DEST); 2542 + SAS_OREJ_BAD_DEST); 2657 2543 break; 2658 2544 2659 2545 case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: 2660 2546 2661 2547 isci_request_set_open_reject_status( 2662 2548 request, task, response_ptr, status_ptr, 2663 - complete_to_host_ptr, SAS_OREJ_STP_NORES); 2549 + SAS_OREJ_STP_NORES); 2664 2550 break; 2665 2551 2666 2552 case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: 2667 2553 2668 2554 isci_request_set_open_reject_status( 2669 2555 request, task, response_ptr, status_ptr, 2670 - complete_to_host_ptr, SAS_OREJ_EPROTO); 2556 + SAS_OREJ_EPROTO); 2671 2557 break; 2672 2558 2673 2559 case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: 2674 2560 2675 2561 isci_request_set_open_reject_status( 2676 2562 request, task, response_ptr, status_ptr, 2677 - complete_to_host_ptr, SAS_OREJ_CONN_RATE); 2563 + SAS_OREJ_CONN_RATE); 2678 2564 break; 2679 2565 2680 2566 case SCU_TASK_DONE_LL_R_ERR: ··· 2706 2592 *response_ptr = SAS_TASK_UNDELIVERED; 2707 2593 *status_ptr = SAM_STAT_TASK_ABORTED; 2708 2594 2709 - if (task->task_proto == SAS_PROTOCOL_SMP) { 2595 + if (task->task_proto == SAS_PROTOCOL_SMP) 2710 2596 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2711 - 2712 - *complete_to_host_ptr = isci_perform_normal_io_completion; 2713 - } else { 2597 + else 2714 2598 clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2715 - 2716 - *complete_to_host_ptr = isci_perform_error_io_completion; 2717 - } 2718 2599 break; 2719 2600 } 2720 - } 2721 - 2722 - /** 2723 - * isci_task_save_for_upper_layer_completion() - This function saves the 2724 - * request for later completion to the upper layer driver. 2725 - * @host: This parameter is a pointer to the host on which the the request 2726 - * should be queued (either as an error or success). 2727 - * @request: This parameter is the completed request. 2728 - * @response: This parameter is the response code for the completed task. 2729 - * @status: This parameter is the status code for the completed task. 2730 - * 2731 - * none. 2732 - */ 2733 - static void isci_task_save_for_upper_layer_completion( 2734 - struct isci_host *host, 2735 - struct isci_request *request, 2736 - enum service_response response, 2737 - enum exec_status status, 2738 - enum isci_completion_selection task_notification_selection) 2739 - { 2740 - struct sas_task *task = isci_request_access_task(request); 2741 - 2742 - task_notification_selection 2743 - = isci_task_set_completion_status(task, response, status, 2744 - task_notification_selection); 2745 - 2746 - /* Tasks aborted specifically by a call to the lldd_abort_task 2747 - * function should not be completed to the host in the regular path. 2748 - */ 2749 - switch (task_notification_selection) { 2750 - 2751 - case isci_perform_normal_io_completion: 2752 - /* Normal notification (task_done) */ 2753 - 2754 - /* Add to the completed list. */ 2755 - list_add(&request->completed_node, 2756 - &host->requests_to_complete); 2757 - 2758 - /* Take the request off the device's pending request list. */ 2759 - list_del_init(&request->dev_node); 2760 - break; 2761 - 2762 - case isci_perform_aborted_io_completion: 2763 - /* No notification to libsas because this request is 2764 - * already in the abort path. 2765 - */ 2766 - /* Wake up whatever process was waiting for this 2767 - * request to complete. 2768 - */ 2769 - WARN_ON(request->io_request_completion == NULL); 2770 - 2771 - if (request->io_request_completion != NULL) { 2772 - 2773 - /* Signal whoever is waiting that this 2774 - * request is complete. 2775 - */ 2776 - complete(request->io_request_completion); 2777 - } 2778 - break; 2779 - 2780 - case isci_perform_error_io_completion: 2781 - /* Use sas_task_abort */ 2782 - /* Add to the aborted list. */ 2783 - list_add(&request->completed_node, 2784 - &host->requests_to_errorback); 2785 - break; 2786 - 2787 - default: 2788 - /* Add to the error to libsas list. */ 2789 - list_add(&request->completed_node, 2790 - &host->requests_to_errorback); 2791 - break; 2792 - } 2793 - dev_dbg(&host->pdev->dev, 2794 - "%s: %d - task = %p, response=%d (%d), status=%d (%d)\n", 2795 - __func__, task_notification_selection, task, 2796 - (task) ? task->task_status.resp : 0, response, 2797 - (task) ? task->task_status.stat : 0, status); 2798 2601 } 2799 2602 2800 2603 static void isci_process_stp_response(struct sas_task *task, struct dev_to_host_fis *fis) ··· 2746 2715 struct isci_remote_device *idev = request->target_device; 2747 2716 enum service_response response = SAS_TASK_UNDELIVERED; 2748 2717 enum exec_status status = SAS_ABORTED_TASK; 2749 - enum isci_request_status request_status; 2750 - enum isci_completion_selection complete_to_host 2751 - = isci_perform_normal_io_completion; 2752 2718 2753 2719 dev_dbg(&ihost->pdev->dev, 2754 - "%s: request = %p, task = %p,\n" 2720 + "%s: request = %p, task = %p, " 2755 2721 "task->data_dir = %d completion_status = 0x%x\n", 2756 - __func__, 2757 - request, 2758 - task, 2759 - task->data_dir, 2760 - completion_status); 2722 + __func__, request, task, task->data_dir, completion_status); 2761 2723 2762 - spin_lock(&request->state_lock); 2763 - request_status = request->status; 2724 + /* The request is done from an SCU HW perspective. */ 2764 2725 2765 - /* Decode the request status. Note that if the request has been 2766 - * aborted by a task management function, we don't care 2767 - * what the status is. 2768 - */ 2769 - switch (request_status) { 2726 + /* This is an active request being completed from the core. */ 2727 + switch (completion_status) { 2770 2728 2771 - case aborted: 2772 - /* "aborted" indicates that the request was aborted by a task 2773 - * management function, since once a task management request is 2774 - * perfomed by the device, the request only completes because 2775 - * of the subsequent driver terminate. 2776 - * 2777 - * Aborted also means an external thread is explicitly managing 2778 - * this request, so that we do not complete it up the stack. 2779 - * 2780 - * The target is still there (since the TMF was successful). 2781 - */ 2729 + case SCI_IO_FAILURE_RESPONSE_VALID: 2730 + dev_dbg(&ihost->pdev->dev, 2731 + "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n", 2732 + __func__, request, task); 2733 + 2734 + if (sas_protocol_ata(task->task_proto)) { 2735 + isci_process_stp_response(task, &request->stp.rsp); 2736 + } else if (SAS_PROTOCOL_SSP == task->task_proto) { 2737 + 2738 + /* crack the iu response buffer. */ 2739 + resp_iu = &request->ssp.rsp; 2740 + isci_request_process_response_iu(task, resp_iu, 2741 + &ihost->pdev->dev); 2742 + 2743 + } else if (SAS_PROTOCOL_SMP == task->task_proto) { 2744 + 2745 + dev_err(&ihost->pdev->dev, 2746 + "%s: SCI_IO_FAILURE_RESPONSE_VALID: " 2747 + "SAS_PROTOCOL_SMP protocol\n", 2748 + __func__); 2749 + 2750 + } else 2751 + dev_err(&ihost->pdev->dev, 2752 + "%s: unknown protocol\n", __func__); 2753 + 2754 + /* use the task status set in the task struct by the 2755 + * isci_request_process_response_iu call. 2756 + */ 2782 2757 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2758 + response = task->task_status.resp; 2759 + status = task->task_status.stat; 2760 + break; 2761 + 2762 + case SCI_IO_SUCCESS: 2763 + case SCI_IO_SUCCESS_IO_DONE_EARLY: 2764 + 2783 2765 response = SAS_TASK_COMPLETE; 2766 + status = SAM_STAT_GOOD; 2767 + set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2768 + 2769 + if (completion_status == SCI_IO_SUCCESS_IO_DONE_EARLY) { 2770 + 2771 + /* This was an SSP / STP / SATA transfer. 2772 + * There is a possibility that less data than 2773 + * the maximum was transferred. 2774 + */ 2775 + u32 transferred_length = sci_req_tx_bytes(request); 2776 + 2777 + task->task_status.residual 2778 + = task->total_xfer_len - transferred_length; 2779 + 2780 + /* If there were residual bytes, call this an 2781 + * underrun. 2782 + */ 2783 + if (task->task_status.residual != 0) 2784 + status = SAS_DATA_UNDERRUN; 2785 + 2786 + dev_dbg(&ihost->pdev->dev, 2787 + "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n", 2788 + __func__, status); 2789 + 2790 + } else 2791 + dev_dbg(&ihost->pdev->dev, "%s: SCI_IO_SUCCESS\n", 2792 + __func__); 2793 + break; 2794 + 2795 + case SCI_IO_FAILURE_TERMINATED: 2796 + 2797 + dev_dbg(&ihost->pdev->dev, 2798 + "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n", 2799 + __func__, request, task); 2800 + 2801 + /* The request was terminated explicitly. */ 2802 + set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2803 + response = SAS_TASK_UNDELIVERED; 2784 2804 2785 2805 /* See if the device has been/is being stopped. Note 2786 - * that we ignore the quiesce state, since we are 2787 - * concerned about the actual device state. 2788 - */ 2806 + * that we ignore the quiesce state, since we are 2807 + * concerned about the actual device state. 2808 + */ 2809 + if (!idev) 2810 + status = SAS_DEVICE_UNKNOWN; 2811 + else 2812 + status = SAS_ABORTED_TASK; 2813 + break; 2814 + 2815 + case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR: 2816 + 2817 + isci_request_handle_controller_specific_errors(idev, request, 2818 + task, &response, 2819 + &status); 2820 + break; 2821 + 2822 + case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: 2823 + /* This is a special case, in that the I/O completion 2824 + * is telling us that the device needs a reset. 2825 + * In order for the device reset condition to be 2826 + * noticed, the I/O has to be handled in the error 2827 + * handler. Set the reset flag and cause the 2828 + * SCSI error thread to be scheduled. 2829 + */ 2830 + spin_lock_irqsave(&task->task_state_lock, task_flags); 2831 + task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; 2832 + spin_unlock_irqrestore(&task->task_state_lock, task_flags); 2833 + 2834 + /* Fail the I/O. */ 2835 + response = SAS_TASK_UNDELIVERED; 2836 + status = SAM_STAT_TASK_ABORTED; 2837 + 2838 + clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2839 + break; 2840 + 2841 + case SCI_FAILURE_RETRY_REQUIRED: 2842 + 2843 + /* Fail the I/O so it can be retried. */ 2844 + response = SAS_TASK_UNDELIVERED; 2789 2845 if (!idev) 2790 2846 status = SAS_DEVICE_UNKNOWN; 2791 2847 else 2792 2848 status = SAS_ABORTED_TASK; 2793 2849 2794 - complete_to_host = isci_perform_aborted_io_completion; 2795 - /* This was an aborted request. */ 2796 - 2797 - spin_unlock(&request->state_lock); 2798 - break; 2799 - 2800 - case aborting: 2801 - /* aborting means that the task management function tried and 2802 - * failed to abort the request. We need to note the request 2803 - * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the 2804 - * target as down. 2805 - * 2806 - * Aborting also means an external thread is explicitly managing 2807 - * this request, so that we do not complete it up the stack. 2808 - */ 2809 2850 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2810 - response = SAS_TASK_UNDELIVERED; 2811 - 2812 - if (!idev) 2813 - /* The device has been /is being stopped. Note that 2814 - * we ignore the quiesce state, since we are 2815 - * concerned about the actual device state. 2816 - */ 2817 - status = SAS_DEVICE_UNKNOWN; 2818 - else 2819 - status = SAS_PHY_DOWN; 2820 - 2821 - complete_to_host = isci_perform_aborted_io_completion; 2822 - 2823 - /* This was an aborted request. */ 2824 - 2825 - spin_unlock(&request->state_lock); 2826 2851 break; 2827 2852 2828 - case terminating: 2829 - 2830 - /* This was an terminated request. This happens when 2831 - * the I/O is being terminated because of an action on 2832 - * the device (reset, tear down, etc.), and the I/O needs 2833 - * to be completed up the stack. 2834 - */ 2835 - set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2836 - response = SAS_TASK_UNDELIVERED; 2837 - 2838 - /* See if the device has been/is being stopped. Note 2839 - * that we ignore the quiesce state, since we are 2840 - * concerned about the actual device state. 2841 - */ 2842 - if (!idev) 2843 - status = SAS_DEVICE_UNKNOWN; 2844 - else 2845 - status = SAS_ABORTED_TASK; 2846 - 2847 - complete_to_host = isci_perform_aborted_io_completion; 2848 - 2849 - /* This was a terminated request. */ 2850 - 2851 - spin_unlock(&request->state_lock); 2852 - break; 2853 - 2854 - case dead: 2855 - /* This was a terminated request that timed-out during the 2856 - * termination process. There is no task to complete to 2857 - * libsas. 2858 - */ 2859 - complete_to_host = isci_perform_normal_io_completion; 2860 - spin_unlock(&request->state_lock); 2861 - break; 2862 2853 2863 2854 default: 2855 + /* Catch any otherwise unhandled error codes here. */ 2856 + dev_dbg(&ihost->pdev->dev, 2857 + "%s: invalid completion code: 0x%x - " 2858 + "isci_request = %p\n", 2859 + __func__, completion_status, request); 2864 2860 2865 - /* The request is done from an SCU HW perspective. */ 2866 - request->status = completed; 2861 + response = SAS_TASK_UNDELIVERED; 2867 2862 2868 - spin_unlock(&request->state_lock); 2863 + /* See if the device has been/is being stopped. Note 2864 + * that we ignore the quiesce state, since we are 2865 + * concerned about the actual device state. 2866 + */ 2867 + if (!idev) 2868 + status = SAS_DEVICE_UNKNOWN; 2869 + else 2870 + status = SAS_ABORTED_TASK; 2869 2871 2870 - /* This is an active request being completed from the core. */ 2871 - switch (completion_status) { 2872 - 2873 - case SCI_IO_FAILURE_RESPONSE_VALID: 2874 - dev_dbg(&ihost->pdev->dev, 2875 - "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n", 2876 - __func__, 2877 - request, 2878 - task); 2879 - 2880 - if (sas_protocol_ata(task->task_proto)) { 2881 - isci_process_stp_response(task, &request->stp.rsp); 2882 - } else if (SAS_PROTOCOL_SSP == task->task_proto) { 2883 - 2884 - /* crack the iu response buffer. */ 2885 - resp_iu = &request->ssp.rsp; 2886 - isci_request_process_response_iu(task, resp_iu, 2887 - &ihost->pdev->dev); 2888 - 2889 - } else if (SAS_PROTOCOL_SMP == task->task_proto) { 2890 - 2891 - dev_err(&ihost->pdev->dev, 2892 - "%s: SCI_IO_FAILURE_RESPONSE_VALID: " 2893 - "SAS_PROTOCOL_SMP protocol\n", 2894 - __func__); 2895 - 2896 - } else 2897 - dev_err(&ihost->pdev->dev, 2898 - "%s: unknown protocol\n", __func__); 2899 - 2900 - /* use the task status set in the task struct by the 2901 - * isci_request_process_response_iu call. 2902 - */ 2872 + if (SAS_PROTOCOL_SMP == task->task_proto) 2903 2873 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2904 - response = task->task_status.resp; 2905 - status = task->task_status.stat; 2906 - break; 2907 - 2908 - case SCI_IO_SUCCESS: 2909 - case SCI_IO_SUCCESS_IO_DONE_EARLY: 2910 - 2911 - response = SAS_TASK_COMPLETE; 2912 - status = SAM_STAT_GOOD; 2913 - set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2914 - 2915 - if (completion_status == SCI_IO_SUCCESS_IO_DONE_EARLY) { 2916 - 2917 - /* This was an SSP / STP / SATA transfer. 2918 - * There is a possibility that less data than 2919 - * the maximum was transferred. 2920 - */ 2921 - u32 transferred_length = sci_req_tx_bytes(request); 2922 - 2923 - task->task_status.residual 2924 - = task->total_xfer_len - transferred_length; 2925 - 2926 - /* If there were residual bytes, call this an 2927 - * underrun. 2928 - */ 2929 - if (task->task_status.residual != 0) 2930 - status = SAS_DATA_UNDERRUN; 2931 - 2932 - dev_dbg(&ihost->pdev->dev, 2933 - "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n", 2934 - __func__, 2935 - status); 2936 - 2937 - } else 2938 - dev_dbg(&ihost->pdev->dev, 2939 - "%s: SCI_IO_SUCCESS\n", 2940 - __func__); 2941 - 2942 - break; 2943 - 2944 - case SCI_IO_FAILURE_TERMINATED: 2945 - dev_dbg(&ihost->pdev->dev, 2946 - "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n", 2947 - __func__, 2948 - request, 2949 - task); 2950 - 2951 - /* The request was terminated explicitly. No handling 2952 - * is needed in the SCSI error handler path. 2953 - */ 2954 - set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2955 - response = SAS_TASK_UNDELIVERED; 2956 - 2957 - /* See if the device has been/is being stopped. Note 2958 - * that we ignore the quiesce state, since we are 2959 - * concerned about the actual device state. 2960 - */ 2961 - if (!idev) 2962 - status = SAS_DEVICE_UNKNOWN; 2963 - else 2964 - status = SAS_ABORTED_TASK; 2965 - 2966 - complete_to_host = isci_perform_normal_io_completion; 2967 - break; 2968 - 2969 - case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR: 2970 - 2971 - isci_request_handle_controller_specific_errors( 2972 - idev, request, task, &response, &status, 2973 - &complete_to_host); 2974 - 2975 - break; 2976 - 2977 - case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: 2978 - /* This is a special case, in that the I/O completion 2979 - * is telling us that the device needs a reset. 2980 - * In order for the device reset condition to be 2981 - * noticed, the I/O has to be handled in the error 2982 - * handler. Set the reset flag and cause the 2983 - * SCSI error thread to be scheduled. 2984 - */ 2985 - spin_lock_irqsave(&task->task_state_lock, task_flags); 2986 - task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; 2987 - spin_unlock_irqrestore(&task->task_state_lock, task_flags); 2988 - 2989 - /* Fail the I/O. */ 2990 - response = SAS_TASK_UNDELIVERED; 2991 - status = SAM_STAT_TASK_ABORTED; 2992 - 2993 - complete_to_host = isci_perform_error_io_completion; 2874 + else 2994 2875 clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 2995 - break; 2996 - 2997 - case SCI_FAILURE_RETRY_REQUIRED: 2998 - 2999 - /* Fail the I/O so it can be retried. */ 3000 - response = SAS_TASK_UNDELIVERED; 3001 - if (!idev) 3002 - status = SAS_DEVICE_UNKNOWN; 3003 - else 3004 - status = SAS_ABORTED_TASK; 3005 - 3006 - complete_to_host = isci_perform_normal_io_completion; 3007 - set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 3008 - break; 3009 - 3010 - 3011 - default: 3012 - /* Catch any otherwise unhandled error codes here. */ 3013 - dev_dbg(&ihost->pdev->dev, 3014 - "%s: invalid completion code: 0x%x - " 3015 - "isci_request = %p\n", 3016 - __func__, completion_status, request); 3017 - 3018 - response = SAS_TASK_UNDELIVERED; 3019 - 3020 - /* See if the device has been/is being stopped. Note 3021 - * that we ignore the quiesce state, since we are 3022 - * concerned about the actual device state. 3023 - */ 3024 - if (!idev) 3025 - status = SAS_DEVICE_UNKNOWN; 3026 - else 3027 - status = SAS_ABORTED_TASK; 3028 - 3029 - if (SAS_PROTOCOL_SMP == task->task_proto) { 3030 - set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 3031 - complete_to_host = isci_perform_normal_io_completion; 3032 - } else { 3033 - clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); 3034 - complete_to_host = isci_perform_error_io_completion; 3035 - } 3036 - break; 3037 - } 3038 2876 break; 3039 2877 } 3040 2878 ··· 2938 3038 break; 2939 3039 } 2940 3040 2941 - /* Put the completed request on the correct list */ 2942 - isci_task_save_for_upper_layer_completion(ihost, request, response, 2943 - status, complete_to_host 2944 - ); 3041 + spin_lock_irqsave(&task->task_state_lock, task_flags); 3042 + 3043 + task->task_status.resp = response; 3044 + task->task_status.stat = status; 3045 + 3046 + if (test_bit(IREQ_COMPLETE_IN_TARGET, &request->flags)) { 3047 + /* Normal notification (task_done) */ 3048 + task->task_state_flags |= SAS_TASK_STATE_DONE; 3049 + task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | 3050 + SAS_TASK_STATE_PENDING); 3051 + } 3052 + spin_unlock_irqrestore(&task->task_state_lock, task_flags); 2945 3053 2946 3054 /* complete the io request to the core. */ 2947 3055 sci_controller_complete_io(ihost, request->target_device, request); ··· 2959 3051 * task to recognize the already completed case. 2960 3052 */ 2961 3053 set_bit(IREQ_TERMINATED, &request->flags); 3054 + 3055 + ireq_done(ihost, request, task); 2962 3056 } 2963 3057 2964 3058 static void sci_request_started_state_enter(struct sci_base_state_machine *sm) ··· 3079 3169 sci_init_sm(&ireq->sm, sci_request_state_table, SCI_REQ_INIT); 3080 3170 3081 3171 ireq->target_device = idev; 3082 - ireq->protocol = SCIC_NO_PROTOCOL; 3172 + ireq->protocol = SAS_PROTOCOL_NONE; 3083 3173 ireq->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX; 3084 3174 3085 3175 ireq->sci_status = SCI_SUCCESS; ··· 3103 3193 3104 3194 if (dev->dev_type == SAS_END_DEV) 3105 3195 /* pass */; 3106 - else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) 3196 + else if (dev_is_sata(dev)) 3107 3197 memset(&ireq->stp.cmd, 0, sizeof(ireq->stp.cmd)); 3108 3198 else if (dev_is_expander(dev)) 3109 3199 /* pass */; ··· 3125 3215 /* Build the common part of the request */ 3126 3216 sci_general_request_construct(ihost, idev, ireq); 3127 3217 3128 - if (dev->dev_type == SAS_END_DEV || 3129 - dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) { 3218 + if (dev->dev_type == SAS_END_DEV || dev_is_sata(dev)) { 3130 3219 set_bit(IREQ_TMF, &ireq->flags); 3131 3220 memset(ireq->tc, 0, sizeof(struct scu_task_context)); 3221 + 3222 + /* Set the protocol indicator. */ 3223 + if (dev_is_sata(dev)) 3224 + ireq->protocol = SAS_PROTOCOL_STP; 3225 + else 3226 + ireq->protocol = SAS_PROTOCOL_SSP; 3132 3227 } else 3133 3228 status = SCI_FAILURE_UNSUPPORTED_PROTOCOL; 3134 3229 ··· 3226 3311 if (!dma_map_sg(dev, sg, 1, DMA_TO_DEVICE)) 3227 3312 return SCI_FAILURE; 3228 3313 3229 - ireq->protocol = SCIC_SMP_PROTOCOL; 3314 + ireq->protocol = SAS_PROTOCOL_SMP; 3230 3315 3231 3316 /* byte swap the smp request. */ 3232 3317 ··· 3411 3496 ireq->io_request_completion = NULL; 3412 3497 ireq->flags = 0; 3413 3498 ireq->num_sg_entries = 0; 3414 - INIT_LIST_HEAD(&ireq->completed_node); 3415 - INIT_LIST_HEAD(&ireq->dev_node); 3416 - isci_request_change_state(ireq, allocated); 3417 3499 3418 3500 return ireq; 3419 3501 } ··· 3494 3582 spin_unlock_irqrestore(&ihost->scic_lock, flags); 3495 3583 return status; 3496 3584 } 3497 - 3498 3585 /* Either I/O started OK, or the core has signaled that 3499 3586 * the device needs a target reset. 3500 - * 3501 - * In either case, hold onto the I/O for later. 3502 - * 3503 - * Update it's status and add it to the list in the 3504 - * remote device object. 3505 3587 */ 3506 - list_add(&ireq->dev_node, &idev->reqs_in_process); 3507 - 3508 - if (status == SCI_SUCCESS) { 3509 - isci_request_change_state(ireq, started); 3510 - } else { 3588 + if (status != SCI_SUCCESS) { 3511 3589 /* The request did not really start in the 3512 3590 * hardware, so clear the request handle 3513 3591 * here so no terminations will be done. 3514 3592 */ 3515 3593 set_bit(IREQ_TERMINATED, &ireq->flags); 3516 - isci_request_change_state(ireq, completed); 3517 3594 } 3518 3595 spin_unlock_irqrestore(&ihost->scic_lock, flags); 3519 3596
+5 -120
drivers/scsi/isci/request.h
··· 61 61 #include "scu_task_context.h" 62 62 63 63 /** 64 - * struct isci_request_status - This enum defines the possible states of an I/O 65 - * request. 66 - * 67 - * 68 - */ 69 - enum isci_request_status { 70 - unallocated = 0x00, 71 - allocated = 0x01, 72 - started = 0x02, 73 - completed = 0x03, 74 - aborting = 0x04, 75 - aborted = 0x05, 76 - terminating = 0x06, 77 - dead = 0x07 78 - }; 79 - 80 - enum sci_request_protocol { 81 - SCIC_NO_PROTOCOL, 82 - SCIC_SMP_PROTOCOL, 83 - SCIC_SSP_PROTOCOL, 84 - SCIC_STP_PROTOCOL 85 - }; /* XXX remove me, use sas_task.{dev|task_proto} instead */; 86 - 87 - /** 88 64 * isci_stp_request - extra request infrastructure to handle pio/atapi protocol 89 65 * @pio_len - number of bytes requested at PIO setup 90 66 * @status - pio setup ending status value to tell us if we need ··· 80 104 }; 81 105 82 106 struct isci_request { 83 - enum isci_request_status status; 84 107 #define IREQ_COMPLETE_IN_TARGET 0 85 108 #define IREQ_TERMINATED 1 86 109 #define IREQ_TMF 2 87 110 #define IREQ_ACTIVE 3 111 + #define IREQ_PENDING_ABORT 4 /* Set == device was not suspended yet */ 112 + #define IREQ_TC_ABORT_POSTED 5 113 + #define IREQ_ABORT_PATH_ACTIVE 6 114 + #define IREQ_NO_AUTO_FREE_TAG 7 /* Set when being explicitly managed */ 88 115 unsigned long flags; 89 116 /* XXX kill ttype and ttype_ptr, allocate full sas_task */ 90 117 union ttype_ptr_union { ··· 95 116 struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */ 96 117 } ttype_ptr; 97 118 struct isci_host *isci_host; 98 - /* For use in the requests_to_{complete|abort} lists: */ 99 - struct list_head completed_node; 100 - /* For use in the reqs_in_process list: */ 101 - struct list_head dev_node; 102 - spinlock_t state_lock; 103 119 dma_addr_t request_daddr; 104 120 dma_addr_t zero_scatter_daddr; 105 121 unsigned int num_sg_entries; ··· 114 140 struct isci_host *owning_controller; 115 141 struct isci_remote_device *target_device; 116 142 u16 io_tag; 117 - enum sci_request_protocol protocol; 143 + enum sas_protocol protocol; 118 144 u32 scu_status; /* hardware result */ 119 145 u32 sci_status; /* upper layer disposition */ 120 146 u32 post_context; ··· 283 309 return ireq->request_daddr + (requested_addr - base_addr); 284 310 } 285 311 286 - /** 287 - * isci_request_change_state() - This function sets the status of the request 288 - * object. 289 - * @request: This parameter points to the isci_request object 290 - * @status: This Parameter is the new status of the object 291 - * 292 - */ 293 - static inline enum isci_request_status 294 - isci_request_change_state(struct isci_request *isci_request, 295 - enum isci_request_status status) 296 - { 297 - enum isci_request_status old_state; 298 - unsigned long flags; 299 - 300 - dev_dbg(&isci_request->isci_host->pdev->dev, 301 - "%s: isci_request = %p, state = 0x%x\n", 302 - __func__, 303 - isci_request, 304 - status); 305 - 306 - BUG_ON(isci_request == NULL); 307 - 308 - spin_lock_irqsave(&isci_request->state_lock, flags); 309 - old_state = isci_request->status; 310 - isci_request->status = status; 311 - spin_unlock_irqrestore(&isci_request->state_lock, flags); 312 - 313 - return old_state; 314 - } 315 - 316 - /** 317 - * isci_request_change_started_to_newstate() - This function sets the status of 318 - * the request object. 319 - * @request: This parameter points to the isci_request object 320 - * @status: This Parameter is the new status of the object 321 - * 322 - * state previous to any change. 323 - */ 324 - static inline enum isci_request_status 325 - isci_request_change_started_to_newstate(struct isci_request *isci_request, 326 - struct completion *completion_ptr, 327 - enum isci_request_status newstate) 328 - { 329 - enum isci_request_status old_state; 330 - unsigned long flags; 331 - 332 - spin_lock_irqsave(&isci_request->state_lock, flags); 333 - 334 - old_state = isci_request->status; 335 - 336 - if (old_state == started || old_state == aborting) { 337 - BUG_ON(isci_request->io_request_completion != NULL); 338 - 339 - isci_request->io_request_completion = completion_ptr; 340 - isci_request->status = newstate; 341 - } 342 - 343 - spin_unlock_irqrestore(&isci_request->state_lock, flags); 344 - 345 - dev_dbg(&isci_request->isci_host->pdev->dev, 346 - "%s: isci_request = %p, old_state = 0x%x\n", 347 - __func__, 348 - isci_request, 349 - old_state); 350 - 351 - return old_state; 352 - } 353 - 354 - /** 355 - * isci_request_change_started_to_aborted() - This function sets the status of 356 - * the request object. 357 - * @request: This parameter points to the isci_request object 358 - * @completion_ptr: This parameter is saved as the kernel completion structure 359 - * signalled when the old request completes. 360 - * 361 - * state previous to any change. 362 - */ 363 - static inline enum isci_request_status 364 - isci_request_change_started_to_aborted(struct isci_request *isci_request, 365 - struct completion *completion_ptr) 366 - { 367 - return isci_request_change_started_to_newstate(isci_request, 368 - completion_ptr, 369 - aborted); 370 - } 371 - 372 312 #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr) 373 313 374 314 #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr) ··· 292 404 u16 tag); 293 405 int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev, 294 406 struct sas_task *task, u16 tag); 295 - void isci_terminate_pending_requests(struct isci_host *ihost, 296 - struct isci_remote_device *idev); 297 407 enum sci_status 298 408 sci_task_request_construct(struct isci_host *ihost, 299 409 struct isci_remote_device *idev, ··· 307 421 task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ); 308 422 309 423 } 310 - 311 424 #endif /* !defined(_ISCI_REQUEST_H_) */
+2
drivers/scsi/isci/scu_completion_codes.h
··· 224 224 * 32-bit value like we want, each immediate value must be cast to a u32. 225 225 */ 226 226 #define SCU_TASK_DONE_GOOD ((u32)0x00) 227 + #define SCU_TASK_DONE_TX_RAW_CMD_ERR ((u32)0x08) 227 228 #define SCU_TASK_DONE_CRC_ERR ((u32)0x14) 228 229 #define SCU_TASK_DONE_CHECK_RESPONSE ((u32)0x14) 229 230 #define SCU_TASK_DONE_GEN_RESPONSE ((u32)0x15) ··· 238 237 #define SCU_TASK_DONE_LL_LF_TERM ((u32)0x1A) 239 238 #define SCU_TASK_DONE_DATA_LEN_ERR ((u32)0x1A) 240 239 #define SCU_TASK_DONE_LL_CL_TERM ((u32)0x1B) 240 + #define SCU_TASK_DONE_BREAK_RCVD ((u32)0x1B) 241 241 #define SCU_TASK_DONE_LL_ABORT_ERR ((u32)0x1B) 242 242 #define SCU_TASK_DONE_SEQ_INV_TYPE ((u32)0x1C) 243 243 #define SCU_TASK_DONE_UNEXP_XR ((u32)0x1C)
+140 -654
drivers/scsi/isci/task.c
··· 78 78 enum exec_status status) 79 79 80 80 { 81 - enum isci_completion_selection disposition; 81 + unsigned long flags; 82 82 83 - disposition = isci_perform_normal_io_completion; 84 - disposition = isci_task_set_completion_status(task, response, status, 85 - disposition); 83 + /* Normal notification (task_done) */ 84 + dev_dbg(&ihost->pdev->dev, "%s: task = %p, response=%d, status=%d\n", 85 + __func__, task, response, status); 86 86 87 - /* Tasks aborted specifically by a call to the lldd_abort_task 88 - * function should not be completed to the host in the regular path. 89 - */ 90 - switch (disposition) { 91 - case isci_perform_normal_io_completion: 92 - /* Normal notification (task_done) */ 93 - dev_dbg(&ihost->pdev->dev, 94 - "%s: Normal - task = %p, response=%d, " 95 - "status=%d\n", 96 - __func__, task, response, status); 87 + spin_lock_irqsave(&task->task_state_lock, flags); 97 88 98 - task->lldd_task = NULL; 99 - task->task_done(task); 100 - break; 89 + task->task_status.resp = response; 90 + task->task_status.stat = status; 101 91 102 - case isci_perform_aborted_io_completion: 103 - /* 104 - * No notification because this request is already in the 105 - * abort path. 106 - */ 107 - dev_dbg(&ihost->pdev->dev, 108 - "%s: Aborted - task = %p, response=%d, " 109 - "status=%d\n", 110 - __func__, task, response, status); 111 - break; 92 + /* Normal notification (task_done) */ 93 + task->task_state_flags |= SAS_TASK_STATE_DONE; 94 + task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | 95 + SAS_TASK_STATE_PENDING); 96 + task->lldd_task = NULL; 97 + spin_unlock_irqrestore(&task->task_state_lock, flags); 112 98 113 - case isci_perform_error_io_completion: 114 - /* Use sas_task_abort */ 115 - dev_dbg(&ihost->pdev->dev, 116 - "%s: Error - task = %p, response=%d, " 117 - "status=%d\n", 118 - __func__, task, response, status); 119 - sas_task_abort(task); 120 - break; 121 - 122 - default: 123 - dev_dbg(&ihost->pdev->dev, 124 - "%s: isci task notification default case!", 125 - __func__); 126 - sas_task_abort(task); 127 - break; 128 - } 99 + task->task_done(task); 129 100 } 130 101 131 102 #define for_each_sas_task(num, task) \ ··· 260 289 return ireq; 261 290 } 262 291 263 - /** 264 - * isci_request_mark_zombie() - This function must be called with scic_lock held. 265 - */ 266 - static void isci_request_mark_zombie(struct isci_host *ihost, struct isci_request *ireq) 267 - { 268 - struct completion *tmf_completion = NULL; 269 - struct completion *req_completion; 270 - 271 - /* Set the request state to "dead". */ 272 - ireq->status = dead; 273 - 274 - req_completion = ireq->io_request_completion; 275 - ireq->io_request_completion = NULL; 276 - 277 - if (test_bit(IREQ_TMF, &ireq->flags)) { 278 - /* Break links with the TMF request. */ 279 - struct isci_tmf *tmf = isci_request_access_tmf(ireq); 280 - 281 - /* In the case where a task request is dying, 282 - * the thread waiting on the complete will sit and 283 - * timeout unless we wake it now. Since the TMF 284 - * has a default error status, complete it here 285 - * to wake the waiting thread. 286 - */ 287 - if (tmf) { 288 - tmf_completion = tmf->complete; 289 - tmf->complete = NULL; 290 - } 291 - ireq->ttype_ptr.tmf_task_ptr = NULL; 292 - dev_dbg(&ihost->pdev->dev, "%s: tmf_code %d, managed tag %#x\n", 293 - __func__, tmf->tmf_code, tmf->io_tag); 294 - } else { 295 - /* Break links with the sas_task - the callback is done 296 - * elsewhere. 297 - */ 298 - struct sas_task *task = isci_request_access_task(ireq); 299 - 300 - if (task) 301 - task->lldd_task = NULL; 302 - 303 - ireq->ttype_ptr.io_task_ptr = NULL; 304 - } 305 - 306 - dev_warn(&ihost->pdev->dev, "task context unrecoverable (tag: %#x)\n", 307 - ireq->io_tag); 308 - 309 - /* Don't force waiting threads to timeout. */ 310 - if (req_completion) 311 - complete(req_completion); 312 - 313 - if (tmf_completion != NULL) 314 - complete(tmf_completion); 315 - } 316 - 317 292 static int isci_task_execute_tmf(struct isci_host *ihost, 318 293 struct isci_remote_device *idev, 319 294 struct isci_tmf *tmf, unsigned long timeout_ms) ··· 317 400 spin_unlock_irqrestore(&ihost->scic_lock, flags); 318 401 goto err_tci; 319 402 } 320 - 321 - if (tmf->cb_state_func != NULL) 322 - tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data); 323 - 324 - isci_request_change_state(ireq, started); 325 - 326 - /* add the request to the remote device request list. */ 327 - list_add(&ireq->dev_node, &idev->reqs_in_process); 328 - 329 403 spin_unlock_irqrestore(&ihost->scic_lock, flags); 404 + 405 + /* The RNC must be unsuspended before the TMF can get a response. */ 406 + isci_remote_device_resume_from_abort(ihost, idev); 330 407 331 408 /* Wait for the TMF to complete, or a timeout. */ 332 409 timeleft = wait_for_completion_timeout(&completion, ··· 330 419 /* The TMF did not complete - this could be because 331 420 * of an unplug. Terminate the TMF request now. 332 421 */ 333 - spin_lock_irqsave(&ihost->scic_lock, flags); 334 - 335 - if (tmf->cb_state_func != NULL) 336 - tmf->cb_state_func(isci_tmf_timed_out, tmf, 337 - tmf->cb_data); 338 - 339 - sci_controller_terminate_request(ihost, idev, ireq); 340 - 341 - spin_unlock_irqrestore(&ihost->scic_lock, flags); 342 - 343 - timeleft = wait_for_completion_timeout( 344 - &completion, 345 - msecs_to_jiffies(ISCI_TERMINATION_TIMEOUT_MSEC)); 346 - 347 - if (!timeleft) { 348 - /* Strange condition - the termination of the TMF 349 - * request timed-out. 350 - */ 351 - spin_lock_irqsave(&ihost->scic_lock, flags); 352 - 353 - /* If the TMF status has not changed, kill it. */ 354 - if (tmf->status == SCI_FAILURE_TIMEOUT) 355 - isci_request_mark_zombie(ihost, ireq); 356 - 357 - spin_unlock_irqrestore(&ihost->scic_lock, flags); 358 - } 422 + isci_remote_device_suspend_terminate(ihost, idev, ireq); 359 423 } 360 424 361 425 isci_print_tmf(ihost, tmf); ··· 362 476 } 363 477 364 478 static void isci_task_build_tmf(struct isci_tmf *tmf, 365 - enum isci_tmf_function_codes code, 366 - void (*tmf_sent_cb)(enum isci_tmf_cb_state, 367 - struct isci_tmf *, 368 - void *), 369 - void *cb_data) 479 + enum isci_tmf_function_codes code) 370 480 { 371 481 memset(tmf, 0, sizeof(*tmf)); 372 - 373 - tmf->tmf_code = code; 374 - tmf->cb_state_func = tmf_sent_cb; 375 - tmf->cb_data = cb_data; 482 + tmf->tmf_code = code; 376 483 } 377 484 378 485 static void isci_task_build_abort_task_tmf(struct isci_tmf *tmf, 379 486 enum isci_tmf_function_codes code, 380 - void (*tmf_sent_cb)(enum isci_tmf_cb_state, 381 - struct isci_tmf *, 382 - void *), 383 487 struct isci_request *old_request) 384 488 { 385 - isci_task_build_tmf(tmf, code, tmf_sent_cb, old_request); 489 + isci_task_build_tmf(tmf, code); 386 490 tmf->io_tag = old_request->io_tag; 387 - } 388 - 389 - /** 390 - * isci_task_validate_request_to_abort() - This function checks the given I/O 391 - * against the "started" state. If the request is still "started", it's 392 - * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD 393 - * BEFORE CALLING THIS FUNCTION. 394 - * @isci_request: This parameter specifies the request object to control. 395 - * @isci_host: This parameter specifies the ISCI host object 396 - * @isci_device: This is the device to which the request is pending. 397 - * @aborted_io_completion: This is a completion structure that will be added to 398 - * the request in case it is changed to aborting; this completion is 399 - * triggered when the request is fully completed. 400 - * 401 - * Either "started" on successful change of the task status to "aborted", or 402 - * "unallocated" if the task cannot be controlled. 403 - */ 404 - static enum isci_request_status isci_task_validate_request_to_abort( 405 - struct isci_request *isci_request, 406 - struct isci_host *isci_host, 407 - struct isci_remote_device *isci_device, 408 - struct completion *aborted_io_completion) 409 - { 410 - enum isci_request_status old_state = unallocated; 411 - 412 - /* Only abort the task if it's in the 413 - * device's request_in_process list 414 - */ 415 - if (isci_request && !list_empty(&isci_request->dev_node)) { 416 - old_state = isci_request_change_started_to_aborted( 417 - isci_request, aborted_io_completion); 418 - 419 - } 420 - 421 - return old_state; 422 - } 423 - 424 - static int isci_request_is_dealloc_managed(enum isci_request_status stat) 425 - { 426 - switch (stat) { 427 - case aborted: 428 - case aborting: 429 - case terminating: 430 - case completed: 431 - case dead: 432 - return true; 433 - default: 434 - return false; 435 - } 436 - } 437 - 438 - /** 439 - * isci_terminate_request_core() - This function will terminate the given 440 - * request, and wait for it to complete. This function must only be called 441 - * from a thread that can wait. Note that the request is terminated and 442 - * completed (back to the host, if started there). 443 - * @ihost: This SCU. 444 - * @idev: The target. 445 - * @isci_request: The I/O request to be terminated. 446 - * 447 - */ 448 - static void isci_terminate_request_core(struct isci_host *ihost, 449 - struct isci_remote_device *idev, 450 - struct isci_request *isci_request) 451 - { 452 - enum sci_status status = SCI_SUCCESS; 453 - bool was_terminated = false; 454 - bool needs_cleanup_handling = false; 455 - unsigned long flags; 456 - unsigned long termination_completed = 1; 457 - struct completion *io_request_completion; 458 - 459 - dev_dbg(&ihost->pdev->dev, 460 - "%s: device = %p; request = %p\n", 461 - __func__, idev, isci_request); 462 - 463 - spin_lock_irqsave(&ihost->scic_lock, flags); 464 - 465 - io_request_completion = isci_request->io_request_completion; 466 - 467 - /* Note that we are not going to control 468 - * the target to abort the request. 469 - */ 470 - set_bit(IREQ_COMPLETE_IN_TARGET, &isci_request->flags); 471 - 472 - /* Make sure the request wasn't just sitting around signalling 473 - * device condition (if the request handle is NULL, then the 474 - * request completed but needed additional handling here). 475 - */ 476 - if (!test_bit(IREQ_TERMINATED, &isci_request->flags)) { 477 - was_terminated = true; 478 - needs_cleanup_handling = true; 479 - status = sci_controller_terminate_request(ihost, 480 - idev, 481 - isci_request); 482 - } 483 - spin_unlock_irqrestore(&ihost->scic_lock, flags); 484 - 485 - /* 486 - * The only time the request to terminate will 487 - * fail is when the io request is completed and 488 - * being aborted. 489 - */ 490 - if (status != SCI_SUCCESS) { 491 - dev_dbg(&ihost->pdev->dev, 492 - "%s: sci_controller_terminate_request" 493 - " returned = 0x%x\n", 494 - __func__, status); 495 - 496 - isci_request->io_request_completion = NULL; 497 - 498 - } else { 499 - if (was_terminated) { 500 - dev_dbg(&ihost->pdev->dev, 501 - "%s: before completion wait (%p/%p)\n", 502 - __func__, isci_request, io_request_completion); 503 - 504 - /* Wait here for the request to complete. */ 505 - termination_completed 506 - = wait_for_completion_timeout( 507 - io_request_completion, 508 - msecs_to_jiffies(ISCI_TERMINATION_TIMEOUT_MSEC)); 509 - 510 - if (!termination_completed) { 511 - 512 - /* The request to terminate has timed out. */ 513 - spin_lock_irqsave(&ihost->scic_lock, flags); 514 - 515 - /* Check for state changes. */ 516 - if (!test_bit(IREQ_TERMINATED, 517 - &isci_request->flags)) { 518 - 519 - /* The best we can do is to have the 520 - * request die a silent death if it 521 - * ever really completes. 522 - */ 523 - isci_request_mark_zombie(ihost, 524 - isci_request); 525 - needs_cleanup_handling = true; 526 - } else 527 - termination_completed = 1; 528 - 529 - spin_unlock_irqrestore(&ihost->scic_lock, 530 - flags); 531 - 532 - if (!termination_completed) { 533 - 534 - dev_dbg(&ihost->pdev->dev, 535 - "%s: *** Timeout waiting for " 536 - "termination(%p/%p)\n", 537 - __func__, io_request_completion, 538 - isci_request); 539 - 540 - /* The request can no longer be referenced 541 - * safely since it may go away if the 542 - * termination every really does complete. 543 - */ 544 - isci_request = NULL; 545 - } 546 - } 547 - if (termination_completed) 548 - dev_dbg(&ihost->pdev->dev, 549 - "%s: after completion wait (%p/%p)\n", 550 - __func__, isci_request, io_request_completion); 551 - } 552 - 553 - if (termination_completed) { 554 - 555 - isci_request->io_request_completion = NULL; 556 - 557 - /* Peek at the status of the request. This will tell 558 - * us if there was special handling on the request such that it 559 - * needs to be detached and freed here. 560 - */ 561 - spin_lock_irqsave(&isci_request->state_lock, flags); 562 - 563 - needs_cleanup_handling 564 - = isci_request_is_dealloc_managed( 565 - isci_request->status); 566 - 567 - spin_unlock_irqrestore(&isci_request->state_lock, flags); 568 - 569 - } 570 - if (needs_cleanup_handling) { 571 - 572 - dev_dbg(&ihost->pdev->dev, 573 - "%s: cleanup isci_device=%p, request=%p\n", 574 - __func__, idev, isci_request); 575 - 576 - if (isci_request != NULL) { 577 - spin_lock_irqsave(&ihost->scic_lock, flags); 578 - isci_free_tag(ihost, isci_request->io_tag); 579 - isci_request_change_state(isci_request, unallocated); 580 - list_del_init(&isci_request->dev_node); 581 - spin_unlock_irqrestore(&ihost->scic_lock, flags); 582 - } 583 - } 584 - } 585 - } 586 - 587 - /** 588 - * isci_terminate_pending_requests() - This function will change the all of the 589 - * requests on the given device's state to "aborting", will terminate the 590 - * requests, and wait for them to complete. This function must only be 591 - * called from a thread that can wait. Note that the requests are all 592 - * terminated and completed (back to the host, if started there). 593 - * @isci_host: This parameter specifies SCU. 594 - * @idev: This parameter specifies the target. 595 - * 596 - */ 597 - void isci_terminate_pending_requests(struct isci_host *ihost, 598 - struct isci_remote_device *idev) 599 - { 600 - struct completion request_completion; 601 - enum isci_request_status old_state; 602 - unsigned long flags; 603 - LIST_HEAD(list); 604 - 605 - spin_lock_irqsave(&ihost->scic_lock, flags); 606 - list_splice_init(&idev->reqs_in_process, &list); 607 - 608 - /* assumes that isci_terminate_request_core deletes from the list */ 609 - while (!list_empty(&list)) { 610 - struct isci_request *ireq = list_entry(list.next, typeof(*ireq), dev_node); 611 - 612 - /* Change state to "terminating" if it is currently 613 - * "started". 614 - */ 615 - old_state = isci_request_change_started_to_newstate(ireq, 616 - &request_completion, 617 - terminating); 618 - switch (old_state) { 619 - case started: 620 - case completed: 621 - case aborting: 622 - break; 623 - default: 624 - /* termination in progress, or otherwise dispositioned. 625 - * We know the request was on 'list' so should be safe 626 - * to move it back to reqs_in_process 627 - */ 628 - list_move(&ireq->dev_node, &idev->reqs_in_process); 629 - ireq = NULL; 630 - break; 631 - } 632 - 633 - if (!ireq) 634 - continue; 635 - spin_unlock_irqrestore(&ihost->scic_lock, flags); 636 - 637 - init_completion(&request_completion); 638 - 639 - dev_dbg(&ihost->pdev->dev, 640 - "%s: idev=%p request=%p; task=%p old_state=%d\n", 641 - __func__, idev, ireq, 642 - (!test_bit(IREQ_TMF, &ireq->flags) 643 - ? isci_request_access_task(ireq) 644 - : NULL), 645 - old_state); 646 - 647 - /* If the old_state is started: 648 - * This request was not already being aborted. If it had been, 649 - * then the aborting I/O (ie. the TMF request) would not be in 650 - * the aborting state, and thus would be terminated here. Note 651 - * that since the TMF completion's call to the kernel function 652 - * "complete()" does not happen until the pending I/O request 653 - * terminate fully completes, we do not have to implement a 654 - * special wait here for already aborting requests - the 655 - * termination of the TMF request will force the request 656 - * to finish it's already started terminate. 657 - * 658 - * If old_state == completed: 659 - * This request completed from the SCU hardware perspective 660 - * and now just needs cleaning up in terms of freeing the 661 - * request and potentially calling up to libsas. 662 - * 663 - * If old_state == aborting: 664 - * This request has already gone through a TMF timeout, but may 665 - * not have been terminated; needs cleaning up at least. 666 - */ 667 - isci_terminate_request_core(ihost, idev, ireq); 668 - spin_lock_irqsave(&ihost->scic_lock, flags); 669 - } 670 - spin_unlock_irqrestore(&ihost->scic_lock, flags); 671 491 } 672 492 673 493 /** ··· 399 807 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or 400 808 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED"). 401 809 */ 402 - isci_task_build_tmf(&tmf, isci_tmf_ssp_lun_reset, NULL, NULL); 810 + isci_task_build_tmf(&tmf, isci_tmf_ssp_lun_reset); 403 811 404 812 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */ 405 813 ret = isci_task_execute_tmf(isci_host, isci_device, &tmf, ISCI_LU_RESET_TIMEOUT_MS); ··· 418 826 419 827 int isci_task_lu_reset(struct domain_device *dev, u8 *lun) 420 828 { 421 - struct isci_host *isci_host = dev_to_ihost(dev); 422 - struct isci_remote_device *isci_device; 829 + struct isci_host *ihost = dev_to_ihost(dev); 830 + struct isci_remote_device *idev; 423 831 unsigned long flags; 424 - int ret; 832 + int ret = TMF_RESP_FUNC_COMPLETE; 425 833 426 - spin_lock_irqsave(&isci_host->scic_lock, flags); 427 - isci_device = isci_lookup_device(dev); 428 - spin_unlock_irqrestore(&isci_host->scic_lock, flags); 834 + spin_lock_irqsave(&ihost->scic_lock, flags); 835 + idev = isci_get_device(dev->lldd_dev); 836 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 429 837 430 - dev_dbg(&isci_host->pdev->dev, 838 + dev_dbg(&ihost->pdev->dev, 431 839 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n", 432 - __func__, dev, isci_host, isci_device); 840 + __func__, dev, ihost, idev); 433 841 434 - if (!isci_device) { 435 - /* If the device is gone, stop the escalations. */ 436 - dev_dbg(&isci_host->pdev->dev, "%s: No dev\n", __func__); 842 + if (!idev) { 843 + /* If the device is gone, escalate to I_T_Nexus_Reset. */ 844 + dev_dbg(&ihost->pdev->dev, "%s: No dev\n", __func__); 437 845 438 - ret = TMF_RESP_FUNC_COMPLETE; 846 + ret = TMF_RESP_FUNC_FAILED; 439 847 goto out; 440 848 } 441 849 442 - /* Send the task management part of the reset. */ 443 - if (dev_is_sata(dev)) { 444 - sas_ata_schedule_reset(dev); 445 - ret = TMF_RESP_FUNC_COMPLETE; 446 - } else 447 - ret = isci_task_send_lu_reset_sas(isci_host, isci_device, lun); 448 - 449 - /* If the LUN reset worked, all the I/O can now be terminated. */ 450 - if (ret == TMF_RESP_FUNC_COMPLETE) 451 - /* Terminate all I/O now. */ 452 - isci_terminate_pending_requests(isci_host, 453 - isci_device); 454 - 850 + /* Suspend the RNC, kill all TCs */ 851 + if (isci_remote_device_suspend_terminate(ihost, idev, NULL) 852 + != SCI_SUCCESS) { 853 + /* The suspend/terminate only fails if isci_get_device fails */ 854 + ret = TMF_RESP_FUNC_FAILED; 855 + goto out; 856 + } 857 + /* All pending I/Os have been terminated and cleaned up. */ 858 + if (!test_bit(IDEV_GONE, &idev->flags)) { 859 + if (dev_is_sata(dev)) 860 + sas_ata_schedule_reset(dev); 861 + else 862 + /* Send the task management part of the reset. */ 863 + ret = isci_task_send_lu_reset_sas(ihost, idev, lun); 864 + } 455 865 out: 456 - isci_put_device(isci_device); 866 + isci_put_device(idev); 457 867 return ret; 458 868 } 459 869 ··· 476 882 /* Task Management Functions. Must be called from process context. */ 477 883 478 884 /** 479 - * isci_abort_task_process_cb() - This is a helper function for the abort task 480 - * TMF command. It manages the request state with respect to the successful 481 - * transmission / completion of the abort task request. 482 - * @cb_state: This parameter specifies when this function was called - after 483 - * the TMF request has been started and after it has timed-out. 484 - * @tmf: This parameter specifies the TMF in progress. 485 - * 486 - * 487 - */ 488 - static void isci_abort_task_process_cb( 489 - enum isci_tmf_cb_state cb_state, 490 - struct isci_tmf *tmf, 491 - void *cb_data) 492 - { 493 - struct isci_request *old_request; 494 - 495 - old_request = (struct isci_request *)cb_data; 496 - 497 - dev_dbg(&old_request->isci_host->pdev->dev, 498 - "%s: tmf=%p, old_request=%p\n", 499 - __func__, tmf, old_request); 500 - 501 - switch (cb_state) { 502 - 503 - case isci_tmf_started: 504 - /* The TMF has been started. Nothing to do here, since the 505 - * request state was already set to "aborted" by the abort 506 - * task function. 507 - */ 508 - if ((old_request->status != aborted) 509 - && (old_request->status != completed)) 510 - dev_dbg(&old_request->isci_host->pdev->dev, 511 - "%s: Bad request status (%d): tmf=%p, old_request=%p\n", 512 - __func__, old_request->status, tmf, old_request); 513 - break; 514 - 515 - case isci_tmf_timed_out: 516 - 517 - /* Set the task's state to "aborting", since the abort task 518 - * function thread set it to "aborted" (above) in anticipation 519 - * of the task management request working correctly. Since the 520 - * timeout has now fired, the TMF request failed. We set the 521 - * state such that the request completion will indicate the 522 - * device is no longer present. 523 - */ 524 - isci_request_change_state(old_request, aborting); 525 - break; 526 - 527 - default: 528 - dev_dbg(&old_request->isci_host->pdev->dev, 529 - "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n", 530 - __func__, cb_state, tmf, old_request); 531 - break; 532 - } 533 - } 534 - 535 - /** 536 885 * isci_task_abort_task() - This function is one of the SAS Domain Template 537 886 * functions. This function is called by libsas to abort a specified task. 538 887 * @task: This parameter specifies the SAS task to abort. ··· 484 947 */ 485 948 int isci_task_abort_task(struct sas_task *task) 486 949 { 487 - struct isci_host *isci_host = dev_to_ihost(task->dev); 950 + struct isci_host *ihost = dev_to_ihost(task->dev); 488 951 DECLARE_COMPLETION_ONSTACK(aborted_io_completion); 489 952 struct isci_request *old_request = NULL; 490 - enum isci_request_status old_state; 491 - struct isci_remote_device *isci_device = NULL; 953 + struct isci_remote_device *idev = NULL; 492 954 struct isci_tmf tmf; 493 955 int ret = TMF_RESP_FUNC_FAILED; 494 956 unsigned long flags; 495 - int perform_termination = 0; 496 957 497 958 /* Get the isci_request reference from the task. Note that 498 959 * this check does not depend on the pending request list 499 960 * in the device, because tasks driving resets may land here 500 961 * after completion in the core. 501 962 */ 502 - spin_lock_irqsave(&isci_host->scic_lock, flags); 963 + spin_lock_irqsave(&ihost->scic_lock, flags); 503 964 spin_lock(&task->task_state_lock); 504 965 505 966 old_request = task->lldd_task; ··· 506 971 if (!(task->task_state_flags & SAS_TASK_STATE_DONE) && 507 972 (task->task_state_flags & SAS_TASK_AT_INITIATOR) && 508 973 old_request) 509 - isci_device = isci_lookup_device(task->dev); 974 + idev = isci_get_device(task->dev->lldd_dev); 510 975 511 976 spin_unlock(&task->task_state_lock); 512 - spin_unlock_irqrestore(&isci_host->scic_lock, flags); 977 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 513 978 514 - dev_dbg(&isci_host->pdev->dev, 515 - "%s: dev = %p, task = %p, old_request == %p\n", 516 - __func__, isci_device, task, old_request); 979 + dev_warn(&ihost->pdev->dev, 980 + "%s: dev = %p (%s%s), task = %p, old_request == %p\n", 981 + __func__, idev, 982 + (dev_is_sata(task->dev) ? "STP/SATA" 983 + : ((dev_is_expander(task->dev)) 984 + ? "SMP" 985 + : "SSP")), 986 + ((idev) ? ((test_bit(IDEV_GONE, &idev->flags)) 987 + ? " IDEV_GONE" 988 + : "") 989 + : " <NULL>"), 990 + task, old_request); 517 991 518 992 /* Device reset conditions signalled in task_state_flags are the 519 993 * responsbility of libsas to observe at the start of the error 520 994 * handler thread. 521 995 */ 522 - if (!isci_device || !old_request) { 996 + if (!idev || !old_request) { 523 997 /* The request has already completed and there 524 998 * is nothing to do here other than to set the task 525 999 * done bit, and indicate that the task abort function ··· 542 998 543 999 ret = TMF_RESP_FUNC_COMPLETE; 544 1000 545 - dev_dbg(&isci_host->pdev->dev, 546 - "%s: abort task not needed for %p\n", 547 - __func__, task); 1001 + dev_warn(&ihost->pdev->dev, 1002 + "%s: abort task not needed for %p\n", 1003 + __func__, task); 548 1004 goto out; 549 1005 } 550 - 551 - spin_lock_irqsave(&isci_host->scic_lock, flags); 552 - 553 - /* Check the request status and change to "aborted" if currently 554 - * "starting"; if true then set the I/O kernel completion 555 - * struct that will be triggered when the request completes. 556 - */ 557 - old_state = isci_task_validate_request_to_abort( 558 - old_request, isci_host, isci_device, 559 - &aborted_io_completion); 560 - if ((old_state != started) && 561 - (old_state != completed) && 562 - (old_state != aborting)) { 563 - 564 - spin_unlock_irqrestore(&isci_host->scic_lock, flags); 565 - 566 - /* The request was already being handled by someone else (because 567 - * they got to set the state away from started). 568 - */ 569 - dev_dbg(&isci_host->pdev->dev, 570 - "%s: device = %p; old_request %p already being aborted\n", 571 - __func__, 572 - isci_device, old_request); 573 - ret = TMF_RESP_FUNC_COMPLETE; 1006 + /* Suspend the RNC, kill the TC */ 1007 + if (isci_remote_device_suspend_terminate(ihost, idev, old_request) 1008 + != SCI_SUCCESS) { 1009 + dev_warn(&ihost->pdev->dev, 1010 + "%s: isci_remote_device_reset_terminate(dev=%p, " 1011 + "req=%p, task=%p) failed\n", 1012 + __func__, idev, old_request, task); 1013 + ret = TMF_RESP_FUNC_FAILED; 574 1014 goto out; 575 1015 } 1016 + spin_lock_irqsave(&ihost->scic_lock, flags); 1017 + 576 1018 if (task->task_proto == SAS_PROTOCOL_SMP || 577 1019 sas_protocol_ata(task->task_proto) || 578 - test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) { 1020 + test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags) || 1021 + test_bit(IDEV_GONE, &idev->flags)) { 579 1022 580 - spin_unlock_irqrestore(&isci_host->scic_lock, flags); 1023 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 581 1024 582 - dev_dbg(&isci_host->pdev->dev, 583 - "%s: %s request" 584 - " or complete_in_target (%d), thus no TMF\n", 585 - __func__, 586 - ((task->task_proto == SAS_PROTOCOL_SMP) 587 - ? "SMP" 588 - : (sas_protocol_ata(task->task_proto) 589 - ? "SATA/STP" 590 - : "<other>") 591 - ), 592 - test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)); 1025 + /* No task to send, so explicitly resume the device here */ 1026 + isci_remote_device_resume_from_abort(ihost, idev); 593 1027 594 - if (test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) { 595 - spin_lock_irqsave(&task->task_state_lock, flags); 596 - task->task_state_flags |= SAS_TASK_STATE_DONE; 597 - task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | 598 - SAS_TASK_STATE_PENDING); 599 - spin_unlock_irqrestore(&task->task_state_lock, flags); 600 - ret = TMF_RESP_FUNC_COMPLETE; 601 - } else { 602 - spin_lock_irqsave(&task->task_state_lock, flags); 603 - task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | 604 - SAS_TASK_STATE_PENDING); 605 - spin_unlock_irqrestore(&task->task_state_lock, flags); 606 - } 1028 + dev_warn(&ihost->pdev->dev, 1029 + "%s: %s request" 1030 + " or complete_in_target (%d), " 1031 + "or IDEV_GONE (%d), thus no TMF\n", 1032 + __func__, 1033 + ((task->task_proto == SAS_PROTOCOL_SMP) 1034 + ? "SMP" 1035 + : (sas_protocol_ata(task->task_proto) 1036 + ? "SATA/STP" 1037 + : "<other>") 1038 + ), 1039 + test_bit(IREQ_COMPLETE_IN_TARGET, 1040 + &old_request->flags), 1041 + test_bit(IDEV_GONE, &idev->flags)); 607 1042 608 - /* STP and SMP devices are not sent a TMF, but the 609 - * outstanding I/O request is terminated below. This is 610 - * because SATA/STP and SMP discovery path timeouts directly 611 - * call the abort task interface for cleanup. 612 - */ 613 - perform_termination = 1; 1043 + spin_lock_irqsave(&task->task_state_lock, flags); 1044 + task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | 1045 + SAS_TASK_STATE_PENDING); 1046 + task->task_state_flags |= SAS_TASK_STATE_DONE; 1047 + spin_unlock_irqrestore(&task->task_state_lock, flags); 614 1048 1049 + ret = TMF_RESP_FUNC_COMPLETE; 615 1050 } else { 616 1051 /* Fill in the tmf stucture */ 617 1052 isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort, 618 - isci_abort_task_process_cb, 619 1053 old_request); 620 1054 621 - spin_unlock_irqrestore(&isci_host->scic_lock, flags); 1055 + spin_unlock_irqrestore(&ihost->scic_lock, flags); 622 1056 1057 + /* Send the task management request. */ 623 1058 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* 1/2 second timeout */ 624 - ret = isci_task_execute_tmf(isci_host, isci_device, &tmf, 1059 + ret = isci_task_execute_tmf(ihost, idev, &tmf, 625 1060 ISCI_ABORT_TASK_TIMEOUT_MS); 626 - 627 - if (ret == TMF_RESP_FUNC_COMPLETE) 628 - perform_termination = 1; 629 - else 630 - dev_dbg(&isci_host->pdev->dev, 631 - "%s: isci_task_send_tmf failed\n", __func__); 632 1061 } 633 - if (perform_termination) { 634 - set_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags); 635 - 636 - /* Clean up the request on our side, and wait for the aborted 637 - * I/O to complete. 638 - */ 639 - isci_terminate_request_core(isci_host, isci_device, 640 - old_request); 641 - } 642 - 643 - /* Make sure we do not leave a reference to aborted_io_completion */ 644 - old_request->io_request_completion = NULL; 645 - out: 646 - isci_put_device(isci_device); 1062 + out: 1063 + dev_warn(&ihost->pdev->dev, 1064 + "%s: Done; dev = %p, task = %p , old_request == %p\n", 1065 + __func__, idev, task, old_request); 1066 + isci_put_device(idev); 647 1067 return ret; 648 1068 } 649 1069 ··· 703 1195 { 704 1196 struct isci_tmf *tmf = isci_request_access_tmf(ireq); 705 1197 struct completion *tmf_complete = NULL; 706 - struct completion *request_complete = ireq->io_request_completion; 707 1198 708 1199 dev_dbg(&ihost->pdev->dev, 709 1200 "%s: request = %p, status=%d\n", 710 1201 __func__, ireq, completion_status); 711 - 712 - isci_request_change_state(ireq, completed); 713 1202 714 1203 set_bit(IREQ_COMPLETE_IN_TARGET, &ireq->flags); 715 1204 ··· 731 1226 */ 732 1227 set_bit(IREQ_TERMINATED, &ireq->flags); 733 1228 734 - /* As soon as something is in the terminate path, deallocation is 735 - * managed there. Note that the final non-managed state of a task 736 - * request is "completed". 737 - */ 738 - if ((ireq->status == completed) || 739 - !isci_request_is_dealloc_managed(ireq->status)) { 740 - isci_request_change_state(ireq, unallocated); 741 - isci_free_tag(ihost, ireq->io_tag); 742 - list_del_init(&ireq->dev_node); 743 - } 1229 + if (test_and_clear_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags)) 1230 + wake_up_all(&ihost->eventq); 744 1231 745 - /* "request_complete" is set if the task was being terminated. */ 746 - if (request_complete) 747 - complete(request_complete); 1232 + if (!test_bit(IREQ_NO_AUTO_FREE_TAG, &ireq->flags)) 1233 + isci_free_tag(ihost, ireq->io_tag); 748 1234 749 1235 /* The task management part completes last. */ 750 1236 if (tmf_complete) ··· 746 1250 struct domain_device *dev, 747 1251 struct isci_remote_device *idev) 748 1252 { 749 - int rc; 750 - unsigned long flags; 751 - enum sci_status status; 1253 + int rc = TMF_RESP_FUNC_COMPLETE, reset_stat = -1; 752 1254 struct sas_phy *phy = sas_get_local_phy(dev); 753 1255 struct isci_port *iport = dev->port->lldd_port; 754 1256 755 1257 dev_dbg(&ihost->pdev->dev, "%s: idev %p\n", __func__, idev); 756 1258 757 - spin_lock_irqsave(&ihost->scic_lock, flags); 758 - status = sci_remote_device_reset(idev); 759 - spin_unlock_irqrestore(&ihost->scic_lock, flags); 760 - 761 - if (status != SCI_SUCCESS) { 762 - dev_dbg(&ihost->pdev->dev, 763 - "%s: sci_remote_device_reset(%p) returned %d!\n", 764 - __func__, idev, status); 1259 + /* Suspend the RNC, terminate all outstanding TCs. */ 1260 + if (isci_remote_device_suspend_terminate(ihost, idev, NULL) 1261 + != SCI_SUCCESS) { 765 1262 rc = TMF_RESP_FUNC_FAILED; 766 1263 goto out; 767 1264 } 1265 + /* Note that since the termination for outstanding requests succeeded, 1266 + * this function will return success. This is because the resets will 1267 + * only fail if the device has been removed (ie. hotplug), and the 1268 + * primary duty of this function is to cleanup tasks, so that is the 1269 + * relevant status. 1270 + */ 1271 + if (!test_bit(IDEV_GONE, &idev->flags)) { 1272 + if (scsi_is_sas_phy_local(phy)) { 1273 + struct isci_phy *iphy = &ihost->phys[phy->number]; 768 1274 769 - if (scsi_is_sas_phy_local(phy)) { 770 - struct isci_phy *iphy = &ihost->phys[phy->number]; 771 - 772 - rc = isci_port_perform_hard_reset(ihost, iport, iphy); 773 - } else 774 - rc = sas_phy_reset(phy, !dev_is_sata(dev)); 775 - 776 - /* Terminate in-progress I/O now. */ 777 - isci_remote_device_nuke_requests(ihost, idev); 778 - 779 - /* Since all pending TCs have been cleaned, resume the RNC. */ 780 - spin_lock_irqsave(&ihost->scic_lock, flags); 781 - status = sci_remote_device_reset_complete(idev); 782 - spin_unlock_irqrestore(&ihost->scic_lock, flags); 783 - 784 - if (status != SCI_SUCCESS) { 785 - dev_dbg(&ihost->pdev->dev, 786 - "%s: sci_remote_device_reset_complete(%p) " 787 - "returned %d!\n", __func__, idev, status); 1275 + reset_stat = isci_port_perform_hard_reset(ihost, iport, 1276 + iphy); 1277 + } else 1278 + reset_stat = sas_phy_reset(phy, !dev_is_sata(dev)); 788 1279 } 1280 + /* Explicitly resume the RNC here, since there was no task sent. */ 1281 + isci_remote_device_resume_from_abort(ihost, idev); 789 1282 790 - dev_dbg(&ihost->pdev->dev, "%s: idev %p complete.\n", __func__, idev); 1283 + dev_dbg(&ihost->pdev->dev, "%s: idev %p complete, reset_stat=%d.\n", 1284 + __func__, idev, reset_stat); 791 1285 out: 792 1286 sas_put_local_phy(phy); 793 1287 return rc; ··· 791 1305 int ret; 792 1306 793 1307 spin_lock_irqsave(&ihost->scic_lock, flags); 794 - idev = isci_lookup_device(dev); 1308 + idev = isci_get_device(dev->lldd_dev); 795 1309 spin_unlock_irqrestore(&ihost->scic_lock, flags); 796 1310 797 1311 if (!idev) {
+1 -131
drivers/scsi/isci/task.h
··· 63 63 struct isci_request; 64 64 65 65 /** 66 - * enum isci_tmf_cb_state - This enum defines the possible states in which the 67 - * TMF callback function is invoked during the TMF execution process. 68 - * 69 - * 70 - */ 71 - enum isci_tmf_cb_state { 72 - 73 - isci_tmf_init_state = 0, 74 - isci_tmf_started, 75 - isci_tmf_timed_out 76 - }; 77 - 78 - /** 79 66 * enum isci_tmf_function_codes - This enum defines the possible preparations 80 67 * of task management requests. 81 68 * ··· 74 87 isci_tmf_ssp_task_abort = TMF_ABORT_TASK, 75 88 isci_tmf_ssp_lun_reset = TMF_LU_RESET, 76 89 }; 90 + 77 91 /** 78 92 * struct isci_tmf - This class represents the task management object which 79 93 * acts as an interface to libsas for processing task management requests ··· 94 106 u16 io_tag; 95 107 enum isci_tmf_function_codes tmf_code; 96 108 int status; 97 - 98 - /* The optional callback function allows the user process to 99 - * track the TMF transmit / timeout conditions. 100 - */ 101 - void (*cb_state_func)( 102 - enum isci_tmf_cb_state, 103 - struct isci_tmf *, void *); 104 - void *cb_data; 105 - 106 109 }; 107 110 108 111 static inline void isci_print_tmf(struct isci_host *ihost, struct isci_tmf *tmf) ··· 187 208 struct scsi_cmnd *scsi_cmd, 188 209 void (*donefunc)(struct scsi_cmnd *)); 189 210 190 - /** 191 - * enum isci_completion_selection - This enum defines the possible actions to 192 - * take with respect to a given request's notification back to libsas. 193 - * 194 - * 195 - */ 196 - enum isci_completion_selection { 197 - 198 - isci_perform_normal_io_completion, /* Normal notify (task_done) */ 199 - isci_perform_aborted_io_completion, /* No notification. */ 200 - isci_perform_error_io_completion /* Use sas_task_abort */ 201 - }; 202 - 203 - /** 204 - * isci_task_set_completion_status() - This function sets the completion status 205 - * for the request. 206 - * @task: This parameter is the completed request. 207 - * @response: This parameter is the response code for the completed task. 208 - * @status: This parameter is the status code for the completed task. 209 - * 210 - * @return The new notification mode for the request. 211 - */ 212 - static inline enum isci_completion_selection 213 - isci_task_set_completion_status( 214 - struct sas_task *task, 215 - enum service_response response, 216 - enum exec_status status, 217 - enum isci_completion_selection task_notification_selection) 218 - { 219 - unsigned long flags; 220 - 221 - spin_lock_irqsave(&task->task_state_lock, flags); 222 - 223 - /* If a device reset is being indicated, make sure the I/O 224 - * is in the error path. 225 - */ 226 - if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) { 227 - /* Fail the I/O to make sure it goes into the error path. */ 228 - response = SAS_TASK_UNDELIVERED; 229 - status = SAM_STAT_TASK_ABORTED; 230 - 231 - task_notification_selection = isci_perform_error_io_completion; 232 - } 233 - task->task_status.resp = response; 234 - task->task_status.stat = status; 235 - 236 - switch (task->task_proto) { 237 - 238 - case SAS_PROTOCOL_SATA: 239 - case SAS_PROTOCOL_STP: 240 - case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: 241 - 242 - if (task_notification_selection 243 - == isci_perform_error_io_completion) { 244 - /* SATA/STP I/O has it's own means of scheduling device 245 - * error handling on the normal path. 246 - */ 247 - task_notification_selection 248 - = isci_perform_normal_io_completion; 249 - } 250 - break; 251 - default: 252 - break; 253 - } 254 - 255 - switch (task_notification_selection) { 256 - 257 - case isci_perform_error_io_completion: 258 - 259 - if (task->task_proto == SAS_PROTOCOL_SMP) { 260 - /* There is no error escalation in the SMP case. 261 - * Convert to a normal completion to avoid the 262 - * timeout in the discovery path and to let the 263 - * next action take place quickly. 264 - */ 265 - task_notification_selection 266 - = isci_perform_normal_io_completion; 267 - 268 - /* Fall through to the normal case... */ 269 - } else { 270 - /* Use sas_task_abort */ 271 - /* Leave SAS_TASK_STATE_DONE clear 272 - * Leave SAS_TASK_AT_INITIATOR set. 273 - */ 274 - break; 275 - } 276 - 277 - case isci_perform_aborted_io_completion: 278 - /* This path can occur with task-managed requests as well as 279 - * requests terminated because of LUN or device resets. 280 - */ 281 - /* Fall through to the normal case... */ 282 - case isci_perform_normal_io_completion: 283 - /* Normal notification (task_done) */ 284 - task->task_state_flags |= SAS_TASK_STATE_DONE; 285 - task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | 286 - SAS_TASK_STATE_PENDING); 287 - break; 288 - default: 289 - WARN_ONCE(1, "unknown task_notification_selection: %d\n", 290 - task_notification_selection); 291 - break; 292 - } 293 - 294 - spin_unlock_irqrestore(&task->task_state_lock, flags); 295 - 296 - return task_notification_selection; 297 - 298 - } 299 211 #endif /* !defined(_SCI_TASK_H_) */
+8 -22
drivers/scsi/isci/unsolicited_frame_control.c
··· 57 57 #include "unsolicited_frame_control.h" 58 58 #include "registers.h" 59 59 60 - int sci_unsolicited_frame_control_construct(struct isci_host *ihost) 60 + void sci_unsolicited_frame_control_construct(struct isci_host *ihost) 61 61 { 62 62 struct sci_unsolicited_frame_control *uf_control = &ihost->uf_control; 63 63 struct sci_unsolicited_frame *uf; 64 - u32 buf_len, header_len, i; 65 - dma_addr_t dma; 66 - size_t size; 67 - void *virt; 68 - 69 - /* 70 - * Prepare all of the memory sizes for the UF headers, UF address 71 - * table, and UF buffers themselves. 72 - */ 73 - buf_len = SCU_MAX_UNSOLICITED_FRAMES * SCU_UNSOLICITED_FRAME_BUFFER_SIZE; 74 - header_len = SCU_MAX_UNSOLICITED_FRAMES * sizeof(struct scu_unsolicited_frame_header); 75 - size = buf_len + header_len + SCU_MAX_UNSOLICITED_FRAMES * sizeof(uf_control->address_table.array[0]); 64 + dma_addr_t dma = ihost->ufi_dma; 65 + void *virt = ihost->ufi_buf; 66 + int i; 76 67 77 68 /* 78 69 * The Unsolicited Frame buffers are set at the start of the UF 79 70 * memory descriptor entry. The headers and address table will be 80 71 * placed after the buffers. 81 72 */ 82 - virt = dmam_alloc_coherent(&ihost->pdev->dev, size, &dma, GFP_KERNEL); 83 - if (!virt) 84 - return -ENOMEM; 85 73 86 74 /* 87 75 * Program the location of the UF header table into the SCU. ··· 81 93 * headers, since we program the UF address table pointers to 82 94 * NULL. 83 95 */ 84 - uf_control->headers.physical_address = dma + buf_len; 85 - uf_control->headers.array = virt + buf_len; 96 + uf_control->headers.physical_address = dma + SCI_UFI_BUF_SIZE; 97 + uf_control->headers.array = virt + SCI_UFI_BUF_SIZE; 86 98 87 99 /* 88 100 * Program the location of the UF address table into the SCU. ··· 91 103 * byte boundary already due to above programming headers being on a 92 104 * 64-bit boundary and headers are on a 64-bytes in size. 93 105 */ 94 - uf_control->address_table.physical_address = dma + buf_len + header_len; 95 - uf_control->address_table.array = virt + buf_len + header_len; 106 + uf_control->address_table.physical_address = dma + SCI_UFI_BUF_SIZE + SCI_UFI_HDR_SIZE; 107 + uf_control->address_table.array = virt + SCI_UFI_BUF_SIZE + SCI_UFI_HDR_SIZE; 96 108 uf_control->get = 0; 97 109 98 110 /* ··· 123 135 virt += SCU_UNSOLICITED_FRAME_BUFFER_SIZE; 124 136 dma += SCU_UNSOLICITED_FRAME_BUFFER_SIZE; 125 137 } 126 - 127 - return 0; 128 138 } 129 139 130 140 enum sci_status sci_unsolicited_frame_control_get_header(struct sci_unsolicited_frame_control *uf_control,
+5 -1
drivers/scsi/isci/unsolicited_frame_control.h
··· 257 257 258 258 }; 259 259 260 + #define SCI_UFI_BUF_SIZE (SCU_MAX_UNSOLICITED_FRAMES * SCU_UNSOLICITED_FRAME_BUFFER_SIZE) 261 + #define SCI_UFI_HDR_SIZE (SCU_MAX_UNSOLICITED_FRAMES * sizeof(struct scu_unsolicited_frame_header)) 262 + #define SCI_UFI_TOTAL_SIZE (SCI_UFI_BUF_SIZE + SCI_UFI_HDR_SIZE + SCU_MAX_UNSOLICITED_FRAMES * sizeof(u64)) 263 + 260 264 struct isci_host; 261 265 262 - int sci_unsolicited_frame_control_construct(struct isci_host *ihost); 266 + void sci_unsolicited_frame_control_construct(struct isci_host *ihost); 263 267 264 268 enum sci_status sci_unsolicited_frame_control_get_header( 265 269 struct sci_unsolicited_frame_control *uf_control,
+1 -1
drivers/scsi/libfc/fc_lport.c
··· 648 648 lport->tt.fcp_abort_io(lport); 649 649 lport->tt.disc_stop_final(lport); 650 650 lport->tt.exch_mgr_reset(lport, 0, 0); 651 + cancel_delayed_work_sync(&lport->retry_work); 651 652 fc_fc4_del_lport(lport); 652 653 return 0; 653 654 } ··· 1565 1564 1566 1565 switch (lport->state) { 1567 1566 case LPORT_ST_DISABLED: 1568 - WARN_ON(1); 1569 1567 break; 1570 1568 case LPORT_ST_READY: 1571 1569 break;
+4
drivers/scsi/lpfc/lpfc.h
··· 93 93 /* lpfc wait event data ready flag */ 94 94 #define LPFC_DATA_READY (1<<0) 95 95 96 + /* queue dump line buffer size */ 97 + #define LPFC_LBUF_SZ 128 98 + 96 99 enum lpfc_polling_flags { 97 100 ENABLE_FCP_RING_POLLING = 0x1, 98 101 DISABLE_FCP_RING_INT = 0x2 ··· 623 620 #define HBA_AER_ENABLED 0x1000 /* AER enabled with HBA */ 624 621 #define HBA_DEVLOSS_TMO 0x2000 /* HBA in devloss timeout */ 625 622 #define HBA_RRQ_ACTIVE 0x4000 /* process the rrq active list */ 623 + #define HBA_FCP_IOQ_FLUSH 0x8000 /* FCP I/O queues being flushed */ 626 624 uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/ 627 625 struct lpfc_dmabuf slim2p; 628 626
+3 -1
drivers/scsi/lpfc/lpfc_bsg.c
··· 1 1 /******************************************************************* 2 2 * This file is part of the Emulex Linux Device Driver for * 3 3 * Fibre Channel Host Bus Adapters. * 4 - * Copyright (C) 2009-2011 Emulex. All rights reserved. * 4 + * Copyright (C) 2009-2012 Emulex. All rights reserved. * 5 5 * EMULEX and SLI are trademarks of Emulex. * 6 6 * www.emulex.com * 7 7 * * ··· 599 599 600 600 cmdiocbq->iocb_cmpl = lpfc_bsg_rport_els_cmp; 601 601 cmdiocbq->context1 = dd_data; 602 + cmdiocbq->context_un.ndlp = ndlp; 602 603 cmdiocbq->context2 = rspiocbq; 603 604 dd_data->type = TYPE_IOCB; 604 605 dd_data->context_un.iocb.cmdiocbq = cmdiocbq; ··· 3979 3978 } else if (subsys == SLI_CONFIG_SUBSYS_COMN) { 3980 3979 switch (opcode) { 3981 3980 case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES: 3981 + case COMN_OPCODE_GET_CNTL_ATTRIBUTES: 3982 3982 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, 3983 3983 "3106 Handled SLI_CONFIG " 3984 3984 "subsys_comn, opcode:x%x\n",
+2 -1
drivers/scsi/lpfc/lpfc_bsg.h
··· 1 1 /******************************************************************* 2 2 * This file is part of the Emulex Linux Device Driver for * 3 3 * Fibre Channel Host Bus Adapters. * 4 - * Copyright (C) 2010 Emulex. All rights reserved. * 4 + * Copyright (C) 2010-2012 Emulex. All rights reserved. * 5 5 * EMULEX and SLI are trademarks of Emulex. * 6 6 * www.emulex.com * 7 7 * * ··· 249 249 #define COMN_OPCODE_READ_OBJECT_LIST 0xAD 250 250 #define COMN_OPCODE_DELETE_OBJECT 0xAE 251 251 #define COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES 0x79 252 + #define COMN_OPCODE_GET_CNTL_ATTRIBUTES 0x20 252 253 uint32_t timeout; 253 254 uint32_t request_length; 254 255 uint32_t word9;
+5 -3
drivers/scsi/lpfc/lpfc_crtn.h
··· 254 254 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *, 255 255 struct lpfc_sli_ring *, uint32_t); 256 256 257 + struct lpfc_iocbq *__lpfc_sli_get_iocbq(struct lpfc_hba *); 257 258 struct lpfc_iocbq * lpfc_sli_get_iocbq(struct lpfc_hba *); 258 259 void lpfc_sli_release_iocbq(struct lpfc_hba *, struct lpfc_iocbq *); 259 260 uint16_t lpfc_sli_next_iotag(struct lpfc_hba *, struct lpfc_iocbq *); ··· 461 460 int lpfc_issue_reg_vfi(struct lpfc_vport *); 462 461 int lpfc_issue_unreg_vfi(struct lpfc_vport *); 463 462 int lpfc_selective_reset(struct lpfc_hba *); 464 - int lpfc_sli4_read_config(struct lpfc_hba *phba); 465 - int lpfc_scsi_buf_update(struct lpfc_hba *phba); 466 - void lpfc_sli4_node_prep(struct lpfc_hba *phba); 463 + int lpfc_sli4_read_config(struct lpfc_hba *); 464 + void lpfc_sli4_node_prep(struct lpfc_hba *); 465 + int lpfc_sli4_xri_sgl_update(struct lpfc_hba *); 466 + void lpfc_free_sgl_list(struct lpfc_hba *, struct list_head *);
+46
drivers/scsi/lpfc/lpfc_debugfs.c
··· 4466 4466 #endif 4467 4467 return; 4468 4468 } 4469 + 4470 + /* 4471 + * Driver debug utility routines outside of debugfs. The debug utility 4472 + * routines implemented here is intended to be used in the instrumented 4473 + * debug driver for debugging host or port issues. 4474 + */ 4475 + 4476 + /** 4477 + * lpfc_debug_dump_all_queues - dump all the queues with a hba 4478 + * @phba: Pointer to HBA context object. 4479 + * 4480 + * This function dumps entries of all the queues asociated with the @phba. 4481 + **/ 4482 + void 4483 + lpfc_debug_dump_all_queues(struct lpfc_hba *phba) 4484 + { 4485 + int fcp_wqidx; 4486 + 4487 + /* 4488 + * Dump Work Queues (WQs) 4489 + */ 4490 + lpfc_debug_dump_mbx_wq(phba); 4491 + lpfc_debug_dump_els_wq(phba); 4492 + 4493 + for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) 4494 + lpfc_debug_dump_fcp_wq(phba, fcp_wqidx); 4495 + 4496 + lpfc_debug_dump_hdr_rq(phba); 4497 + lpfc_debug_dump_dat_rq(phba); 4498 + /* 4499 + * Dump Complete Queues (CQs) 4500 + */ 4501 + lpfc_debug_dump_mbx_cq(phba); 4502 + lpfc_debug_dump_els_cq(phba); 4503 + 4504 + for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) 4505 + lpfc_debug_dump_fcp_cq(phba, fcp_wqidx); 4506 + 4507 + /* 4508 + * Dump Event Queues (EQs) 4509 + */ 4510 + lpfc_debug_dump_sp_eq(phba); 4511 + 4512 + for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) 4513 + lpfc_debug_dump_fcp_eq(phba, fcp_wqidx); 4514 + }
+418
drivers/scsi/lpfc/lpfc_debugfs.h
··· 267 267 #define LPFC_DISC_TRC_DISCOVERY 0xef /* common mask for general 268 268 * discovery */ 269 269 #endif /* H_LPFC_DEBUG_FS */ 270 + 271 + 272 + /* 273 + * Driver debug utility routines outside of debugfs. The debug utility 274 + * routines implemented here is intended to be used in the instrumented 275 + * debug driver for debugging host or port issues. 276 + */ 277 + 278 + /** 279 + * lpfc_debug_dump_qe - dump an specific entry from a queue 280 + * @q: Pointer to the queue descriptor. 281 + * @idx: Index to the entry on the queue. 282 + * 283 + * This function dumps an entry indexed by @idx from a queue specified by the 284 + * queue descriptor @q. 285 + **/ 286 + static inline void 287 + lpfc_debug_dump_qe(struct lpfc_queue *q, uint32_t idx) 288 + { 289 + char line_buf[LPFC_LBUF_SZ]; 290 + int i, esize, qe_word_cnt, len; 291 + uint32_t *pword; 292 + 293 + /* sanity checks */ 294 + if (!q) 295 + return; 296 + if (idx >= q->entry_count) 297 + return; 298 + 299 + esize = q->entry_size; 300 + qe_word_cnt = esize / sizeof(uint32_t); 301 + pword = q->qe[idx].address; 302 + 303 + len = 0; 304 + len += snprintf(line_buf+len, LPFC_LBUF_SZ-len, "QE[%04d]: ", idx); 305 + if (qe_word_cnt > 8) 306 + printk(KERN_ERR "%s\n", line_buf); 307 + 308 + for (i = 0; i < qe_word_cnt; i++) { 309 + if (!(i % 8)) { 310 + if (i != 0) 311 + printk(KERN_ERR "%s\n", line_buf); 312 + if (qe_word_cnt > 8) { 313 + len = 0; 314 + memset(line_buf, 0, LPFC_LBUF_SZ); 315 + len += snprintf(line_buf+len, LPFC_LBUF_SZ-len, 316 + "%03d: ", i); 317 + } 318 + } 319 + len += snprintf(line_buf+len, LPFC_LBUF_SZ-len, "%08x ", 320 + ((uint32_t)*pword) & 0xffffffff); 321 + pword++; 322 + } 323 + if (qe_word_cnt <= 8 || (i - 1) % 8) 324 + printk(KERN_ERR "%s\n", line_buf); 325 + } 326 + 327 + /** 328 + * lpfc_debug_dump_q - dump all entries from an specific queue 329 + * @q: Pointer to the queue descriptor. 330 + * 331 + * This function dumps all entries from a queue specified by the queue 332 + * descriptor @q. 333 + **/ 334 + static inline void 335 + lpfc_debug_dump_q(struct lpfc_queue *q) 336 + { 337 + int idx, entry_count; 338 + 339 + /* sanity check */ 340 + if (!q) 341 + return; 342 + 343 + dev_printk(KERN_ERR, &(((q->phba))->pcidev)->dev, 344 + "%d: [qid:%d, type:%d, subtype:%d, " 345 + "qe_size:%d, qe_count:%d, " 346 + "host_index:%d, port_index:%d]\n", 347 + (q->phba)->brd_no, 348 + q->queue_id, q->type, q->subtype, 349 + q->entry_size, q->entry_count, 350 + q->host_index, q->hba_index); 351 + entry_count = q->entry_count; 352 + for (idx = 0; idx < entry_count; idx++) 353 + lpfc_debug_dump_qe(q, idx); 354 + printk(KERN_ERR "\n"); 355 + } 356 + 357 + /** 358 + * lpfc_debug_dump_fcp_wq - dump all entries from a fcp work queue 359 + * @phba: Pointer to HBA context object. 360 + * @fcp_wqidx: Index to a FCP work queue. 361 + * 362 + * This function dumps all entries from a FCP work queue specified by the 363 + * @fcp_wqidx. 364 + **/ 365 + static inline void 366 + lpfc_debug_dump_fcp_wq(struct lpfc_hba *phba, int fcp_wqidx) 367 + { 368 + /* sanity check */ 369 + if (fcp_wqidx >= phba->cfg_fcp_wq_count) 370 + return; 371 + 372 + printk(KERN_ERR "FCP WQ: WQ[Idx:%d|Qid:%d]\n", 373 + fcp_wqidx, phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id); 374 + lpfc_debug_dump_q(phba->sli4_hba.fcp_wq[fcp_wqidx]); 375 + } 376 + 377 + /** 378 + * lpfc_debug_dump_fcp_cq - dump all entries from a fcp work queue's cmpl queue 379 + * @phba: Pointer to HBA context object. 380 + * @fcp_wqidx: Index to a FCP work queue. 381 + * 382 + * This function dumps all entries from a FCP complete queue which is 383 + * associated to the FCP work queue specified by the @fcp_wqidx. 384 + **/ 385 + static inline void 386 + lpfc_debug_dump_fcp_cq(struct lpfc_hba *phba, int fcp_wqidx) 387 + { 388 + int fcp_cqidx, fcp_cqid; 389 + 390 + /* sanity check */ 391 + if (fcp_wqidx >= phba->cfg_fcp_wq_count) 392 + return; 393 + 394 + fcp_cqid = phba->sli4_hba.fcp_wq[fcp_wqidx]->assoc_qid; 395 + for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) 396 + if (phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id == fcp_cqid) 397 + break; 398 + if (fcp_cqidx >= phba->cfg_fcp_eq_count) 399 + return; 400 + 401 + printk(KERN_ERR "FCP CQ: WQ[Idx:%d|Qid%d]->CQ[Idx%d|Qid%d]:\n", 402 + fcp_wqidx, phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, 403 + fcp_cqidx, fcp_cqid); 404 + lpfc_debug_dump_q(phba->sli4_hba.fcp_cq[fcp_cqidx]); 405 + } 406 + 407 + /** 408 + * lpfc_debug_dump_fcp_eq - dump all entries from a fcp work queue's evt queue 409 + * @phba: Pointer to HBA context object. 410 + * @fcp_wqidx: Index to a FCP work queue. 411 + * 412 + * This function dumps all entries from a FCP event queue which is 413 + * associated to the FCP work queue specified by the @fcp_wqidx. 414 + **/ 415 + static inline void 416 + lpfc_debug_dump_fcp_eq(struct lpfc_hba *phba, int fcp_wqidx) 417 + { 418 + struct lpfc_queue *qdesc; 419 + int fcp_eqidx, fcp_eqid; 420 + int fcp_cqidx, fcp_cqid; 421 + 422 + /* sanity check */ 423 + if (fcp_wqidx >= phba->cfg_fcp_wq_count) 424 + return; 425 + fcp_cqid = phba->sli4_hba.fcp_wq[fcp_wqidx]->assoc_qid; 426 + for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) 427 + if (phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id == fcp_cqid) 428 + break; 429 + if (fcp_cqidx >= phba->cfg_fcp_eq_count) 430 + return; 431 + 432 + if (phba->cfg_fcp_eq_count == 0) { 433 + fcp_eqidx = -1; 434 + fcp_eqid = phba->sli4_hba.sp_eq->queue_id; 435 + qdesc = phba->sli4_hba.sp_eq; 436 + } else { 437 + fcp_eqidx = fcp_cqidx; 438 + fcp_eqid = phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id; 439 + qdesc = phba->sli4_hba.fp_eq[fcp_eqidx]; 440 + } 441 + 442 + printk(KERN_ERR "FCP EQ: WQ[Idx:%d|Qid:%d]->CQ[Idx:%d|Qid:%d]->" 443 + "EQ[Idx:%d|Qid:%d]\n", 444 + fcp_wqidx, phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, 445 + fcp_cqidx, fcp_cqid, fcp_eqidx, fcp_eqid); 446 + lpfc_debug_dump_q(qdesc); 447 + } 448 + 449 + /** 450 + * lpfc_debug_dump_els_wq - dump all entries from the els work queue 451 + * @phba: Pointer to HBA context object. 452 + * 453 + * This function dumps all entries from the ELS work queue. 454 + **/ 455 + static inline void 456 + lpfc_debug_dump_els_wq(struct lpfc_hba *phba) 457 + { 458 + printk(KERN_ERR "ELS WQ: WQ[Qid:%d]:\n", 459 + phba->sli4_hba.els_wq->queue_id); 460 + lpfc_debug_dump_q(phba->sli4_hba.els_wq); 461 + } 462 + 463 + /** 464 + * lpfc_debug_dump_mbx_wq - dump all entries from the mbox work queue 465 + * @phba: Pointer to HBA context object. 466 + * 467 + * This function dumps all entries from the MBOX work queue. 468 + **/ 469 + static inline void 470 + lpfc_debug_dump_mbx_wq(struct lpfc_hba *phba) 471 + { 472 + printk(KERN_ERR "MBX WQ: WQ[Qid:%d]\n", 473 + phba->sli4_hba.mbx_wq->queue_id); 474 + lpfc_debug_dump_q(phba->sli4_hba.mbx_wq); 475 + } 476 + 477 + /** 478 + * lpfc_debug_dump_dat_rq - dump all entries from the receive data queue 479 + * @phba: Pointer to HBA context object. 480 + * 481 + * This function dumps all entries from the receive data queue. 482 + **/ 483 + static inline void 484 + lpfc_debug_dump_dat_rq(struct lpfc_hba *phba) 485 + { 486 + printk(KERN_ERR "DAT RQ: RQ[Qid:%d]\n", 487 + phba->sli4_hba.dat_rq->queue_id); 488 + lpfc_debug_dump_q(phba->sli4_hba.dat_rq); 489 + } 490 + 491 + /** 492 + * lpfc_debug_dump_hdr_rq - dump all entries from the receive header queue 493 + * @phba: Pointer to HBA context object. 494 + * 495 + * This function dumps all entries from the receive header queue. 496 + **/ 497 + static inline void 498 + lpfc_debug_dump_hdr_rq(struct lpfc_hba *phba) 499 + { 500 + printk(KERN_ERR "HDR RQ: RQ[Qid:%d]\n", 501 + phba->sli4_hba.hdr_rq->queue_id); 502 + lpfc_debug_dump_q(phba->sli4_hba.hdr_rq); 503 + } 504 + 505 + /** 506 + * lpfc_debug_dump_els_cq - dump all entries from the els complete queue 507 + * @phba: Pointer to HBA context object. 508 + * 509 + * This function dumps all entries from the els complete queue. 510 + **/ 511 + static inline void 512 + lpfc_debug_dump_els_cq(struct lpfc_hba *phba) 513 + { 514 + printk(KERN_ERR "ELS CQ: WQ[Qid:%d]->CQ[Qid:%d]\n", 515 + phba->sli4_hba.els_wq->queue_id, 516 + phba->sli4_hba.els_cq->queue_id); 517 + lpfc_debug_dump_q(phba->sli4_hba.els_cq); 518 + } 519 + 520 + /** 521 + * lpfc_debug_dump_mbx_cq - dump all entries from the mbox complete queue 522 + * @phba: Pointer to HBA context object. 523 + * 524 + * This function dumps all entries from the mbox complete queue. 525 + **/ 526 + static inline void 527 + lpfc_debug_dump_mbx_cq(struct lpfc_hba *phba) 528 + { 529 + printk(KERN_ERR "MBX CQ: WQ[Qid:%d]->CQ[Qid:%d]\n", 530 + phba->sli4_hba.mbx_wq->queue_id, 531 + phba->sli4_hba.mbx_cq->queue_id); 532 + lpfc_debug_dump_q(phba->sli4_hba.mbx_cq); 533 + } 534 + 535 + /** 536 + * lpfc_debug_dump_sp_eq - dump all entries from slow-path event queue 537 + * @phba: Pointer to HBA context object. 538 + * 539 + * This function dumps all entries from the slow-path event queue. 540 + **/ 541 + static inline void 542 + lpfc_debug_dump_sp_eq(struct lpfc_hba *phba) 543 + { 544 + printk(KERN_ERR "SP EQ: WQ[Qid:%d/Qid:%d]->CQ[Qid:%d/Qid:%d]->" 545 + "EQ[Qid:%d]:\n", 546 + phba->sli4_hba.mbx_wq->queue_id, 547 + phba->sli4_hba.els_wq->queue_id, 548 + phba->sli4_hba.mbx_cq->queue_id, 549 + phba->sli4_hba.els_cq->queue_id, 550 + phba->sli4_hba.sp_eq->queue_id); 551 + lpfc_debug_dump_q(phba->sli4_hba.sp_eq); 552 + } 553 + 554 + /** 555 + * lpfc_debug_dump_wq_by_id - dump all entries from a work queue by queue id 556 + * @phba: Pointer to HBA context object. 557 + * @qid: Work queue identifier. 558 + * 559 + * This function dumps all entries from a work queue identified by the queue 560 + * identifier. 561 + **/ 562 + static inline void 563 + lpfc_debug_dump_wq_by_id(struct lpfc_hba *phba, int qid) 564 + { 565 + int wq_idx; 566 + 567 + for (wq_idx = 0; wq_idx < phba->cfg_fcp_wq_count; wq_idx++) 568 + if (phba->sli4_hba.fcp_wq[wq_idx]->queue_id == qid) 569 + break; 570 + if (wq_idx < phba->cfg_fcp_wq_count) { 571 + printk(KERN_ERR "FCP WQ[Idx:%d|Qid:%d]\n", wq_idx, qid); 572 + lpfc_debug_dump_q(phba->sli4_hba.fcp_wq[wq_idx]); 573 + return; 574 + } 575 + 576 + if (phba->sli4_hba.els_wq->queue_id == qid) { 577 + printk(KERN_ERR "ELS WQ[Qid:%d]\n", qid); 578 + lpfc_debug_dump_q(phba->sli4_hba.els_wq); 579 + } 580 + } 581 + 582 + /** 583 + * lpfc_debug_dump_mq_by_id - dump all entries from a mbox queue by queue id 584 + * @phba: Pointer to HBA context object. 585 + * @qid: Mbox work queue identifier. 586 + * 587 + * This function dumps all entries from a mbox work queue identified by the 588 + * queue identifier. 589 + **/ 590 + static inline void 591 + lpfc_debug_dump_mq_by_id(struct lpfc_hba *phba, int qid) 592 + { 593 + if (phba->sli4_hba.mbx_wq->queue_id == qid) { 594 + printk(KERN_ERR "MBX WQ[Qid:%d]\n", qid); 595 + lpfc_debug_dump_q(phba->sli4_hba.mbx_wq); 596 + } 597 + } 598 + 599 + /** 600 + * lpfc_debug_dump_rq_by_id - dump all entries from a receive queue by queue id 601 + * @phba: Pointer to HBA context object. 602 + * @qid: Receive queue identifier. 603 + * 604 + * This function dumps all entries from a receive queue identified by the 605 + * queue identifier. 606 + **/ 607 + static inline void 608 + lpfc_debug_dump_rq_by_id(struct lpfc_hba *phba, int qid) 609 + { 610 + if (phba->sli4_hba.hdr_rq->queue_id == qid) { 611 + printk(KERN_ERR "HDR RQ[Qid:%d]\n", qid); 612 + lpfc_debug_dump_q(phba->sli4_hba.hdr_rq); 613 + return; 614 + } 615 + if (phba->sli4_hba.dat_rq->queue_id == qid) { 616 + printk(KERN_ERR "DAT RQ[Qid:%d]\n", qid); 617 + lpfc_debug_dump_q(phba->sli4_hba.dat_rq); 618 + } 619 + } 620 + 621 + /** 622 + * lpfc_debug_dump_cq_by_id - dump all entries from a cmpl queue by queue id 623 + * @phba: Pointer to HBA context object. 624 + * @qid: Complete queue identifier. 625 + * 626 + * This function dumps all entries from a complete queue identified by the 627 + * queue identifier. 628 + **/ 629 + static inline void 630 + lpfc_debug_dump_cq_by_id(struct lpfc_hba *phba, int qid) 631 + { 632 + int cq_idx = 0; 633 + 634 + do { 635 + if (phba->sli4_hba.fcp_cq[cq_idx]->queue_id == qid) 636 + break; 637 + } while (++cq_idx < phba->cfg_fcp_eq_count); 638 + 639 + if (cq_idx < phba->cfg_fcp_eq_count) { 640 + printk(KERN_ERR "FCP CQ[Idx:%d|Qid:%d]\n", cq_idx, qid); 641 + lpfc_debug_dump_q(phba->sli4_hba.fcp_cq[cq_idx]); 642 + return; 643 + } 644 + 645 + if (phba->sli4_hba.els_cq->queue_id == qid) { 646 + printk(KERN_ERR "ELS CQ[Qid:%d]\n", qid); 647 + lpfc_debug_dump_q(phba->sli4_hba.els_cq); 648 + return; 649 + } 650 + 651 + if (phba->sli4_hba.mbx_cq->queue_id == qid) { 652 + printk(KERN_ERR "MBX CQ[Qid:%d]\n", qid); 653 + lpfc_debug_dump_q(phba->sli4_hba.mbx_cq); 654 + } 655 + } 656 + 657 + /** 658 + * lpfc_debug_dump_eq_by_id - dump all entries from an event queue by queue id 659 + * @phba: Pointer to HBA context object. 660 + * @qid: Complete queue identifier. 661 + * 662 + * This function dumps all entries from an event queue identified by the 663 + * queue identifier. 664 + **/ 665 + static inline void 666 + lpfc_debug_dump_eq_by_id(struct lpfc_hba *phba, int qid) 667 + { 668 + int eq_idx; 669 + 670 + for (eq_idx = 0; eq_idx < phba->cfg_fcp_eq_count; eq_idx++) { 671 + if (phba->sli4_hba.fp_eq[eq_idx]->queue_id == qid) 672 + break; 673 + } 674 + 675 + if (eq_idx < phba->cfg_fcp_eq_count) { 676 + printk(KERN_ERR "FCP EQ[Idx:%d|Qid:%d]\n", eq_idx, qid); 677 + lpfc_debug_dump_q(phba->sli4_hba.fp_eq[eq_idx]); 678 + return; 679 + } 680 + 681 + if (phba->sli4_hba.sp_eq->queue_id == qid) { 682 + printk(KERN_ERR "SP EQ[|Qid:%d]\n", qid); 683 + lpfc_debug_dump_q(phba->sli4_hba.sp_eq); 684 + } 685 + } 686 + 687 + void lpfc_debug_dump_all_queues(struct lpfc_hba *);
+115 -26
drivers/scsi/lpfc/lpfc_els.c
··· 230 230 231 231 INIT_LIST_HEAD(&pbuflist->list); 232 232 233 - icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); 234 - icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); 235 - icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; 236 - icmd->un.elsreq64.remoteID = did; /* DID */ 237 233 if (expectRsp) { 234 + icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); 235 + icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); 236 + icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; 238 237 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); 238 + 239 + icmd->un.elsreq64.remoteID = did; /* DID */ 239 240 icmd->ulpCommand = CMD_ELS_REQUEST64_CR; 240 241 icmd->ulpTimeout = phba->fc_ratov * 2; 241 242 } else { 242 - icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); 243 + icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); 244 + icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys); 245 + icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; 246 + icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64); 247 + icmd->un.xseq64.xmit_els_remoteID = did; /* DID */ 243 248 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; 244 249 } 245 250 icmd->ulpBdeCount = 1; 246 251 icmd->ulpLe = 1; 247 252 icmd->ulpClass = CLASS3; 248 253 249 - if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { 250 - icmd->un.elsreq64.myID = vport->fc_myDID; 254 + /* 255 + * If we have NPIV enabled, we want to send ELS traffic by VPI. 256 + * For SLI4, since the driver controls VPIs we also want to include 257 + * all ELS pt2pt protocol traffic as well. 258 + */ 259 + if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) || 260 + ((phba->sli_rev == LPFC_SLI_REV4) && 261 + (vport->fc_flag & FC_PT2PT))) { 251 262 252 - /* For ELS_REQUEST64_CR, use the VPI by default */ 253 - icmd->ulpContext = phba->vpi_ids[vport->vpi]; 263 + if (expectRsp) { 264 + icmd->un.elsreq64.myID = vport->fc_myDID; 265 + 266 + /* For ELS_REQUEST64_CR, use the VPI by default */ 267 + icmd->ulpContext = phba->vpi_ids[vport->vpi]; 268 + } 269 + 254 270 icmd->ulpCt_h = 0; 255 271 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ 256 272 if (elscmd == ELS_CMD_ECHO) ··· 454 438 int rc = 0; 455 439 456 440 sp = &phba->fc_fabparam; 457 - /* move forward in case of SLI4 FC port loopback test */ 441 + /* move forward in case of SLI4 FC port loopback test and pt2pt mode */ 458 442 if ((phba->sli_rev == LPFC_SLI_REV4) && 459 - !(phba->link_flag & LS_LOOPBACK_MODE)) { 443 + !(phba->link_flag & LS_LOOPBACK_MODE) && 444 + !(vport->fc_flag & FC_PT2PT)) { 460 445 ndlp = lpfc_findnode_did(vport, Fabric_DID); 461 446 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { 462 447 rc = -ENODEV; ··· 724 707 lpfc_sli4_unreg_all_rpis(vport); 725 708 lpfc_mbx_unreg_vpi(vport); 726 709 spin_lock_irq(shost->host_lock); 727 - vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 728 - /* 729 - * If VPI is unreged, driver need to do INIT_VPI 730 - * before re-registering 731 - */ 732 710 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; 733 711 spin_unlock_irq(shost->host_lock); 734 712 } 713 + 714 + /* 715 + * For SLI3 and SLI4, the VPI needs to be reregistered in 716 + * response to this fabric parameter change event. 717 + */ 718 + spin_lock_irq(shost->host_lock); 719 + vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 720 + spin_unlock_irq(shost->host_lock); 735 721 } else if ((phba->sli_rev == LPFC_SLI_REV4) && 736 722 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { 737 723 /* ··· 837 817 mempool_free(mbox, phba->mbox_mem_pool); 838 818 goto fail; 839 819 } 820 + 821 + /* 822 + * For SLI4, the VFI/VPI are registered AFTER the 823 + * Nport with the higher WWPN sends the PLOGI with 824 + * an assigned NPortId. 825 + */ 826 + 827 + /* not equal */ 828 + if ((phba->sli_rev == LPFC_SLI_REV4) && rc) 829 + lpfc_issue_reg_vfi(vport); 830 + 840 831 /* Decrement ndlp reference count indicating that ndlp can be 841 832 * safely released when other references to it are done. 842 833 */ ··· 3003 2972 * ABTS we cannot generate and RRQ. 3004 2973 */ 3005 2974 lpfc_set_rrq_active(phba, ndlp, 3006 - cmdiocb->sli4_xritag, 0, 0); 2975 + cmdiocb->sli4_lxritag, 0, 0); 3007 2976 } 3008 2977 break; 3009 2978 case IOSTAT_LOCAL_REJECT: ··· 3834 3803 /* Xmit ELS ACC response tag <ulpIoTag> */ 3835 3804 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 3836 3805 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " 3837 - "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", 3806 + "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " 3807 + "fc_flag x%x\n", 3838 3808 elsiocb->iotag, elsiocb->iocb.ulpContext, 3839 3809 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 3840 - ndlp->nlp_rpi); 3810 + ndlp->nlp_rpi, vport->fc_flag); 3841 3811 if (ndlp->nlp_flag & NLP_LOGO_ACC) { 3842 3812 spin_lock_irq(shost->host_lock); 3843 3813 ndlp->nlp_flag &= ~NLP_LOGO_ACC; ··· 4968 4936 return 1; 4969 4937 } 4970 4938 4971 - did = Fabric_DID; 4972 - 4973 4939 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { 4974 4940 /* For a FLOGI we accept, then if our portname is greater 4975 4941 * then the remote portname we initiate Nport login. ··· 5006 4976 spin_lock_irq(shost->host_lock); 5007 4977 vport->fc_flag |= FC_PT2PT_PLOGI; 5008 4978 spin_unlock_irq(shost->host_lock); 4979 + 4980 + /* If we have the high WWPN we can assign our own 4981 + * myDID; otherwise, we have to WAIT for a PLOGI 4982 + * from the remote NPort to find out what it 4983 + * will be. 4984 + */ 4985 + vport->fc_myDID = PT2PT_LocalID; 5009 4986 } 4987 + 4988 + /* 4989 + * The vport state should go to LPFC_FLOGI only 4990 + * AFTER we issue a FLOGI, not receive one. 4991 + */ 5010 4992 spin_lock_irq(shost->host_lock); 5011 4993 vport->fc_flag |= FC_PT2PT; 5012 4994 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); 5013 4995 spin_unlock_irq(shost->host_lock); 4996 + 4997 + /* 4998 + * We temporarily set fc_myDID to make it look like we are 4999 + * a Fabric. This is done just so we end up with the right 5000 + * did / sid on the FLOGI ACC rsp. 5001 + */ 5002 + did = vport->fc_myDID; 5003 + vport->fc_myDID = Fabric_DID; 5004 + 5014 5005 } else { 5015 5006 /* Reject this request because invalid parameters */ 5016 5007 stat.un.b.lsRjtRsvd0 = 0; 5017 5008 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 5018 5009 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; 5019 5010 stat.un.b.vendorUnique = 0; 5011 + 5012 + /* 5013 + * We temporarily set fc_myDID to make it look like we are 5014 + * a Fabric. This is done just so we end up with the right 5015 + * did / sid on the FLOGI LS_RJT rsp. 5016 + */ 5017 + did = vport->fc_myDID; 5018 + vport->fc_myDID = Fabric_DID; 5019 + 5020 5020 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, 5021 5021 NULL); 5022 + 5023 + /* Now lets put fc_myDID back to what its supposed to be */ 5024 + vport->fc_myDID = did; 5025 + 5022 5026 return 1; 5023 5027 } 5024 5028 5025 5029 /* Send back ACC */ 5026 5030 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); 5027 5031 5032 + /* Now lets put fc_myDID back to what its supposed to be */ 5033 + vport->fc_myDID = did; 5034 + 5035 + if (!(vport->fc_flag & FC_PT2PT_PLOGI)) { 5036 + 5037 + mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 5038 + if (!mbox) 5039 + goto fail; 5040 + 5041 + lpfc_config_link(phba, mbox); 5042 + 5043 + mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 5044 + mbox->vport = vport; 5045 + rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 5046 + if (rc == MBX_NOT_FINISHED) { 5047 + mempool_free(mbox, phba->mbox_mem_pool); 5048 + goto fail; 5049 + } 5050 + } 5051 + 5028 5052 return 0; 5053 + fail: 5054 + return 1; 5029 5055 } 5030 5056 5031 5057 /** ··· 5262 5176 } 5263 5177 5264 5178 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); 5265 - mempool_free(pmb, phba->mbox_mem_pool); 5266 5179 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, 5267 5180 lpfc_max_els_tries, ndlp, 5268 5181 ndlp->nlp_DID, ELS_CMD_ACC); ··· 5269 5184 /* Decrement the ndlp reference count from previous mbox command */ 5270 5185 lpfc_nlp_put(ndlp); 5271 5186 5272 - if (!elsiocb) 5187 + if (!elsiocb) { 5188 + mempool_free(pmb, phba->mbox_mem_pool); 5273 5189 return; 5190 + } 5274 5191 5275 5192 icmd = &elsiocb->iocb; 5276 5193 icmd->ulpContext = rxid; ··· 5289 5202 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); 5290 5203 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); 5291 5204 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); 5292 - 5205 + mempool_free(pmb, phba->mbox_mem_pool); 5293 5206 /* Xmit ELS RLS ACC response tag <ulpIoTag> */ 5294 5207 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, 5295 5208 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " ··· 5673 5586 pcmd += sizeof(uint32_t); 5674 5587 els_rrq = (struct RRQ *) pcmd; 5675 5588 5676 - bf_set(rrq_oxid, els_rrq, rrq->xritag); 5589 + bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]); 5677 5590 bf_set(rrq_rxid, els_rrq, rrq->rxid); 5678 5591 bf_set(rrq_did, els_rrq, vport->fc_myDID); 5679 5592 els_rrq->rrq = cpu_to_be32(els_rrq->rrq); ··· 7960 7873 sglq_entry->state = SGL_FREED; 7961 7874 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); 7962 7875 spin_unlock_irqrestore(&phba->hbalock, iflag); 7963 - lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1); 7876 + lpfc_set_rrq_active(phba, ndlp, 7877 + sglq_entry->sli4_lxritag, 7878 + rxid, 1); 7964 7879 7965 7880 /* Check if TXQ queue needs to be serviced */ 7966 7881 if (pring->txq_cnt)
+12 -6
drivers/scsi/lpfc/lpfc_hbadisc.c
··· 713 713 int rc; 714 714 715 715 set_user_nice(current, -20); 716 + current->flags |= PF_NOFREEZE; 716 717 phba->data_flags = 0; 717 718 718 719 while (!kthread_should_stop()) { ··· 1095 1094 /* Start discovery by sending a FLOGI. port_state is identically 1096 1095 * LPFC_FLOGI while waiting for FLOGI cmpl 1097 1096 */ 1098 - if (vport->port_state != LPFC_FLOGI) 1097 + if (vport->port_state != LPFC_FLOGI || vport->fc_flag & FC_PT2PT_PLOGI) 1099 1098 lpfc_initial_flogi(vport); 1100 1099 return; 1101 1100 ··· 2882 2881 } 2883 2882 2884 2883 if (vport->port_state == LPFC_FABRIC_CFG_LINK) { 2885 - /* For private loop just start discovery and we are done. */ 2886 - if ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && 2887 - !(vport->fc_flag & FC_PUBLIC_LOOP)) { 2884 + /* 2885 + * For private loop or for NPort pt2pt, 2886 + * just start discovery and we are done. 2887 + */ 2888 + if ((vport->fc_flag & FC_PT2PT) || 2889 + ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && 2890 + !(vport->fc_flag & FC_PUBLIC_LOOP))) { 2891 + 2888 2892 /* Use loop map to make discovery list */ 2889 2893 lpfc_disc_list_loopmap(vport); 2890 2894 /* Start discovery */ ··· 5496 5490 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); 5497 5491 5498 5492 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, 5499 - "0279 lpfc_nlp_release: ndlp:x%p " 5493 + "0279 lpfc_nlp_release: ndlp:x%p did %x " 5500 5494 "usgmap:x%x refcnt:%d\n", 5501 - (void *)ndlp, ndlp->nlp_usg_map, 5495 + (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, 5502 5496 atomic_read(&ndlp->kref.refcount)); 5503 5497 5504 5498 /* remove ndlp from action. */
+3
drivers/scsi/lpfc/lpfc_hw.h
··· 3374 3374 WORD5 w5; /* Header control/status word */ 3375 3375 } XMT_SEQ_FIELDS64; 3376 3376 3377 + /* This word is remote ports D_ID for XMIT_ELS_RSP64 */ 3378 + #define xmit_els_remoteID xrsqRo 3379 + 3377 3380 /* IOCB Command template for 64 bit RCV_SEQUENCE64 */ 3378 3381 typedef struct { 3379 3382 struct ulp_bde64 rcvBde;
+10 -8
drivers/scsi/lpfc/lpfc_hw4.h
··· 228 228 #define lpfc_idx_rsrc_rdy_MASK 0x00000001 229 229 #define lpfc_idx_rsrc_rdy_WORD word0 230 230 #define LPFC_IDX_RSRC_RDY 1 231 - #define lpfc_xri_rsrc_rdy_SHIFT 1 232 - #define lpfc_xri_rsrc_rdy_MASK 0x00000001 233 - #define lpfc_xri_rsrc_rdy_WORD word0 234 - #define LPFC_XRI_RSRC_RDY 1 235 - #define lpfc_rpi_rsrc_rdy_SHIFT 2 231 + #define lpfc_rpi_rsrc_rdy_SHIFT 1 236 232 #define lpfc_rpi_rsrc_rdy_MASK 0x00000001 237 233 #define lpfc_rpi_rsrc_rdy_WORD word0 238 234 #define LPFC_RPI_RSRC_RDY 1 239 - #define lpfc_vpi_rsrc_rdy_SHIFT 3 235 + #define lpfc_vpi_rsrc_rdy_SHIFT 2 240 236 #define lpfc_vpi_rsrc_rdy_MASK 0x00000001 241 237 #define lpfc_vpi_rsrc_rdy_WORD word0 242 238 #define LPFC_VPI_RSRC_RDY 1 243 - #define lpfc_vfi_rsrc_rdy_SHIFT 4 239 + #define lpfc_vfi_rsrc_rdy_SHIFT 3 244 240 #define lpfc_vfi_rsrc_rdy_MASK 0x00000001 245 241 #define lpfc_vfi_rsrc_rdy_WORD word0 246 242 #define LPFC_VFI_RSRC_RDY 1 ··· 3295 3299 struct xmit_els_rsp64_wqe { 3296 3300 struct ulp_bde64 bde; 3297 3301 uint32_t response_payload_len; 3298 - uint32_t rsvd4; 3302 + uint32_t word4; 3303 + #define els_rsp64_sid_SHIFT 0 3304 + #define els_rsp64_sid_MASK 0x00FFFFFF 3305 + #define els_rsp64_sid_WORD word4 3306 + #define els_rsp64_sp_SHIFT 24 3307 + #define els_rsp64_sp_MASK 0x00000001 3308 + #define els_rsp64_sp_WORD word4 3299 3309 struct wqe_did wqe_dest; 3300 3310 struct wqe_common wqe_com; /* words 6-11 */ 3301 3311 uint32_t word12;
+226 -151
drivers/scsi/lpfc/lpfc_init.c
··· 64 64 static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); 65 65 static int lpfc_setup_endian_order(struct lpfc_hba *); 66 66 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); 67 - static void lpfc_free_sgl_list(struct lpfc_hba *); 68 - static int lpfc_init_sgl_list(struct lpfc_hba *); 67 + static void lpfc_free_els_sgl_list(struct lpfc_hba *); 68 + static void lpfc_init_sgl_list(struct lpfc_hba *); 69 69 static int lpfc_init_active_sgl_array(struct lpfc_hba *); 70 70 static void lpfc_free_active_sgl(struct lpfc_hba *); 71 71 static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); ··· 2767 2767 } 2768 2768 2769 2769 /** 2770 - * lpfc_scsi_buf_update - Update the scsi_buffers that are already allocated. 2771 - * @phba: pointer to lpfc hba data structure. 2772 - * 2773 - * This routine goes through all the scsi buffers in the system and updates the 2774 - * Physical XRIs assigned to the SCSI buffer because these may change after any 2775 - * firmware reset 2776 - * 2777 - * Return codes 2778 - * 0 - successful (for now, it always returns 0) 2779 - **/ 2780 - int 2781 - lpfc_scsi_buf_update(struct lpfc_hba *phba) 2782 - { 2783 - struct lpfc_scsi_buf *sb, *sb_next; 2784 - 2785 - spin_lock_irq(&phba->hbalock); 2786 - spin_lock(&phba->scsi_buf_list_lock); 2787 - list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { 2788 - sb->cur_iocbq.sli4_xritag = 2789 - phba->sli4_hba.xri_ids[sb->cur_iocbq.sli4_lxritag]; 2790 - set_bit(sb->cur_iocbq.sli4_lxritag, phba->sli4_hba.xri_bmask); 2791 - phba->sli4_hba.max_cfg_param.xri_used++; 2792 - phba->sli4_hba.xri_count++; 2793 - } 2794 - spin_unlock(&phba->scsi_buf_list_lock); 2795 - spin_unlock_irq(&phba->hbalock); 2796 - return 0; 2797 - } 2798 - 2799 - /** 2800 2770 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists 2801 2771 * @phba: pointer to lpfc hba data structure. 2802 2772 * 2803 2773 * This routine is to free all the SCSI buffers and IOCBs from the driver 2804 2774 * list back to kernel. It is called from lpfc_pci_remove_one to free 2805 2775 * the internal resources before the device is removed from the system. 2806 - * 2807 - * Return codes 2808 - * 0 - successful (for now, it always returns 0) 2809 2776 **/ 2810 - static int 2777 + static void 2811 2778 lpfc_scsi_free(struct lpfc_hba *phba) 2812 2779 { 2813 2780 struct lpfc_scsi_buf *sb, *sb_next; ··· 2800 2833 } 2801 2834 2802 2835 spin_unlock_irq(&phba->hbalock); 2836 + } 2837 + 2838 + /** 2839 + * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping 2840 + * @phba: pointer to lpfc hba data structure. 2841 + * 2842 + * This routine first calculates the sizes of the current els and allocated 2843 + * scsi sgl lists, and then goes through all sgls to updates the physical 2844 + * XRIs assigned due to port function reset. During port initialization, the 2845 + * current els and allocated scsi sgl lists are 0s. 2846 + * 2847 + * Return codes 2848 + * 0 - successful (for now, it always returns 0) 2849 + **/ 2850 + int 2851 + lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) 2852 + { 2853 + struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; 2854 + struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; 2855 + uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; 2856 + LIST_HEAD(els_sgl_list); 2857 + LIST_HEAD(scsi_sgl_list); 2858 + int rc; 2859 + 2860 + /* 2861 + * update on pci function's els xri-sgl list 2862 + */ 2863 + els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); 2864 + if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { 2865 + /* els xri-sgl expanded */ 2866 + xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; 2867 + lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 2868 + "3157 ELS xri-sgl count increased from " 2869 + "%d to %d\n", phba->sli4_hba.els_xri_cnt, 2870 + els_xri_cnt); 2871 + /* allocate the additional els sgls */ 2872 + for (i = 0; i < xri_cnt; i++) { 2873 + sglq_entry = kzalloc(sizeof(struct lpfc_sglq), 2874 + GFP_KERNEL); 2875 + if (sglq_entry == NULL) { 2876 + lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 2877 + "2562 Failure to allocate an " 2878 + "ELS sgl entry:%d\n", i); 2879 + rc = -ENOMEM; 2880 + goto out_free_mem; 2881 + } 2882 + sglq_entry->buff_type = GEN_BUFF_TYPE; 2883 + sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, 2884 + &sglq_entry->phys); 2885 + if (sglq_entry->virt == NULL) { 2886 + kfree(sglq_entry); 2887 + lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 2888 + "2563 Failure to allocate an " 2889 + "ELS mbuf:%d\n", i); 2890 + rc = -ENOMEM; 2891 + goto out_free_mem; 2892 + } 2893 + sglq_entry->sgl = sglq_entry->virt; 2894 + memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); 2895 + sglq_entry->state = SGL_FREED; 2896 + list_add_tail(&sglq_entry->list, &els_sgl_list); 2897 + } 2898 + spin_lock(&phba->hbalock); 2899 + list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); 2900 + spin_unlock(&phba->hbalock); 2901 + } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { 2902 + /* els xri-sgl shrinked */ 2903 + xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; 2904 + lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 2905 + "3158 ELS xri-sgl count decreased from " 2906 + "%d to %d\n", phba->sli4_hba.els_xri_cnt, 2907 + els_xri_cnt); 2908 + spin_lock_irq(&phba->hbalock); 2909 + list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); 2910 + spin_unlock_irq(&phba->hbalock); 2911 + /* release extra els sgls from list */ 2912 + for (i = 0; i < xri_cnt; i++) { 2913 + list_remove_head(&els_sgl_list, 2914 + sglq_entry, struct lpfc_sglq, list); 2915 + if (sglq_entry) { 2916 + lpfc_mbuf_free(phba, sglq_entry->virt, 2917 + sglq_entry->phys); 2918 + kfree(sglq_entry); 2919 + } 2920 + } 2921 + spin_lock_irq(&phba->hbalock); 2922 + list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); 2923 + spin_unlock_irq(&phba->hbalock); 2924 + } else 2925 + lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 2926 + "3163 ELS xri-sgl count unchanged: %d\n", 2927 + els_xri_cnt); 2928 + phba->sli4_hba.els_xri_cnt = els_xri_cnt; 2929 + 2930 + /* update xris to els sgls on the list */ 2931 + sglq_entry = NULL; 2932 + sglq_entry_next = NULL; 2933 + list_for_each_entry_safe(sglq_entry, sglq_entry_next, 2934 + &phba->sli4_hba.lpfc_sgl_list, list) { 2935 + lxri = lpfc_sli4_next_xritag(phba); 2936 + if (lxri == NO_XRI) { 2937 + lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 2938 + "2400 Failed to allocate xri for " 2939 + "ELS sgl\n"); 2940 + rc = -ENOMEM; 2941 + goto out_free_mem; 2942 + } 2943 + sglq_entry->sli4_lxritag = lxri; 2944 + sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; 2945 + } 2946 + 2947 + /* 2948 + * update on pci function's allocated scsi xri-sgl list 2949 + */ 2950 + phba->total_scsi_bufs = 0; 2951 + 2952 + /* maximum number of xris available for scsi buffers */ 2953 + phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - 2954 + els_xri_cnt; 2955 + 2956 + lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 2957 + "2401 Current allocated SCSI xri-sgl count:%d, " 2958 + "maximum SCSI xri count:%d\n", 2959 + phba->sli4_hba.scsi_xri_cnt, 2960 + phba->sli4_hba.scsi_xri_max); 2961 + 2962 + spin_lock_irq(&phba->scsi_buf_list_lock); 2963 + list_splice_init(&phba->lpfc_scsi_buf_list, &scsi_sgl_list); 2964 + spin_unlock_irq(&phba->scsi_buf_list_lock); 2965 + 2966 + if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { 2967 + /* max scsi xri shrinked below the allocated scsi buffers */ 2968 + scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - 2969 + phba->sli4_hba.scsi_xri_max; 2970 + /* release the extra allocated scsi buffers */ 2971 + for (i = 0; i < scsi_xri_cnt; i++) { 2972 + list_remove_head(&scsi_sgl_list, psb, 2973 + struct lpfc_scsi_buf, list); 2974 + pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data, 2975 + psb->dma_handle); 2976 + kfree(psb); 2977 + } 2978 + spin_lock_irq(&phba->scsi_buf_list_lock); 2979 + phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; 2980 + spin_unlock_irq(&phba->scsi_buf_list_lock); 2981 + } 2982 + 2983 + /* update xris associated to remaining allocated scsi buffers */ 2984 + psb = NULL; 2985 + psb_next = NULL; 2986 + list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { 2987 + lxri = lpfc_sli4_next_xritag(phba); 2988 + if (lxri == NO_XRI) { 2989 + lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 2990 + "2560 Failed to allocate xri for " 2991 + "scsi buffer\n"); 2992 + rc = -ENOMEM; 2993 + goto out_free_mem; 2994 + } 2995 + psb->cur_iocbq.sli4_lxritag = lxri; 2996 + psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; 2997 + } 2998 + spin_lock(&phba->scsi_buf_list_lock); 2999 + list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list); 3000 + spin_unlock(&phba->scsi_buf_list_lock); 3001 + 2803 3002 return 0; 3003 + 3004 + out_free_mem: 3005 + lpfc_free_els_sgl_list(phba); 3006 + lpfc_scsi_free(phba); 3007 + return rc; 2804 3008 } 2805 3009 2806 3010 /** ··· 4774 4636 if (rc) 4775 4637 goto out_free_bsmbx; 4776 4638 4777 - /* Initialize and populate the iocb list per host */ 4778 - rc = lpfc_init_sgl_list(phba); 4779 - if (rc) { 4780 - lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4781 - "1400 Failed to initialize sgl list.\n"); 4782 - goto out_destroy_cq_event_pool; 4783 - } 4639 + /* Initialize sgl lists per host */ 4640 + lpfc_init_sgl_list(phba); 4641 + 4642 + /* Allocate and initialize active sgl array */ 4784 4643 rc = lpfc_init_active_sgl_array(phba); 4785 4644 if (rc) { 4786 4645 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4787 4646 "1430 Failed to initialize sgl list.\n"); 4788 - goto out_free_sgl_list; 4647 + goto out_destroy_cq_event_pool; 4789 4648 } 4790 4649 rc = lpfc_sli4_init_rpi_hdrs(phba); 4791 4650 if (rc) { ··· 4857 4722 lpfc_sli4_remove_rpi_hdrs(phba); 4858 4723 out_free_active_sgl: 4859 4724 lpfc_free_active_sgl(phba); 4860 - out_free_sgl_list: 4861 - lpfc_free_sgl_list(phba); 4862 4725 out_destroy_cq_event_pool: 4863 4726 lpfc_sli4_cq_event_pool_destroy(phba); 4864 4727 out_free_bsmbx: ··· 4893 4760 4894 4761 /* Free the ELS sgl list */ 4895 4762 lpfc_free_active_sgl(phba); 4896 - lpfc_free_sgl_list(phba); 4897 - 4898 - /* Free the SCSI sgl management array */ 4899 - kfree(phba->sli4_hba.lpfc_scsi_psb_array); 4763 + lpfc_free_els_sgl_list(phba); 4900 4764 4901 4765 /* Free the completion queue EQ event pool */ 4902 4766 lpfc_sli4_cq_event_release_all(phba); ··· 5120 4990 } 5121 4991 5122 4992 /** 5123 - * lpfc_free_sgl_list - Free sgl list. 4993 + * lpfc_free_sgl_list - Free a given sgl list. 5124 4994 * @phba: pointer to lpfc hba data structure. 4995 + * @sglq_list: pointer to the head of sgl list. 5125 4996 * 5126 - * This routine is invoked to free the driver's sgl list and memory. 4997 + * This routine is invoked to free a give sgl list and memory. 5127 4998 **/ 5128 - static void 5129 - lpfc_free_sgl_list(struct lpfc_hba *phba) 4999 + void 5000 + lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list) 5130 5001 { 5131 5002 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; 5003 + 5004 + list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { 5005 + list_del(&sglq_entry->list); 5006 + lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); 5007 + kfree(sglq_entry); 5008 + } 5009 + } 5010 + 5011 + /** 5012 + * lpfc_free_els_sgl_list - Free els sgl list. 5013 + * @phba: pointer to lpfc hba data structure. 5014 + * 5015 + * This routine is invoked to free the driver's els sgl list and memory. 5016 + **/ 5017 + static void 5018 + lpfc_free_els_sgl_list(struct lpfc_hba *phba) 5019 + { 5132 5020 LIST_HEAD(sglq_list); 5133 5021 5022 + /* Retrieve all els sgls from driver list */ 5134 5023 spin_lock_irq(&phba->hbalock); 5135 5024 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); 5136 5025 spin_unlock_irq(&phba->hbalock); 5137 5026 5138 - list_for_each_entry_safe(sglq_entry, sglq_next, 5139 - &sglq_list, list) { 5140 - list_del(&sglq_entry->list); 5141 - lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); 5142 - kfree(sglq_entry); 5143 - phba->sli4_hba.total_sglq_bufs--; 5144 - } 5145 - kfree(phba->sli4_hba.lpfc_els_sgl_array); 5027 + /* Now free the sgl list */ 5028 + lpfc_free_sgl_list(phba, &sglq_list); 5146 5029 } 5147 5030 5148 5031 /** ··· 5200 5057 * This routine is invoked to allocate and initizlize the driver's sgl 5201 5058 * list and set up the sgl xritag tag array accordingly. 5202 5059 * 5203 - * Return codes 5204 - * 0 - successful 5205 - * other values - error 5206 5060 **/ 5207 - static int 5061 + static void 5208 5062 lpfc_init_sgl_list(struct lpfc_hba *phba) 5209 5063 { 5210 - struct lpfc_sglq *sglq_entry = NULL; 5211 - int i; 5212 - int els_xri_cnt; 5213 - 5214 - els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); 5215 - lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 5216 - "2400 ELS XRI count %d.\n", 5217 - els_xri_cnt); 5218 5064 /* Initialize and populate the sglq list per host/VF. */ 5219 5065 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); 5220 5066 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); 5221 5067 5222 - /* Sanity check on XRI management */ 5223 - if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) { 5224 - lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 5225 - "2562 No room left for SCSI XRI allocation: " 5226 - "max_xri=%d, els_xri=%d\n", 5227 - phba->sli4_hba.max_cfg_param.max_xri, 5228 - els_xri_cnt); 5229 - return -ENOMEM; 5230 - } 5068 + /* els xri-sgl book keeping */ 5069 + phba->sli4_hba.els_xri_cnt = 0; 5231 5070 5232 - /* Allocate memory for the ELS XRI management array */ 5233 - phba->sli4_hba.lpfc_els_sgl_array = 5234 - kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt), 5235 - GFP_KERNEL); 5236 - 5237 - if (!phba->sli4_hba.lpfc_els_sgl_array) { 5238 - lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 5239 - "2401 Failed to allocate memory for ELS " 5240 - "XRI management array of size %d.\n", 5241 - els_xri_cnt); 5242 - return -ENOMEM; 5243 - } 5244 - 5245 - /* Keep the SCSI XRI into the XRI management array */ 5246 - phba->sli4_hba.scsi_xri_max = 5247 - phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; 5071 + /* scsi xri-buffer book keeping */ 5248 5072 phba->sli4_hba.scsi_xri_cnt = 0; 5249 - phba->sli4_hba.lpfc_scsi_psb_array = 5250 - kzalloc((sizeof(struct lpfc_scsi_buf *) * 5251 - phba->sli4_hba.scsi_xri_max), GFP_KERNEL); 5252 - 5253 - if (!phba->sli4_hba.lpfc_scsi_psb_array) { 5254 - lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 5255 - "2563 Failed to allocate memory for SCSI " 5256 - "XRI management array of size %d.\n", 5257 - phba->sli4_hba.scsi_xri_max); 5258 - kfree(phba->sli4_hba.lpfc_els_sgl_array); 5259 - return -ENOMEM; 5260 - } 5261 - 5262 - for (i = 0; i < els_xri_cnt; i++) { 5263 - sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL); 5264 - if (sglq_entry == NULL) { 5265 - printk(KERN_ERR "%s: only allocated %d sgls of " 5266 - "expected %d count. Unloading driver.\n", 5267 - __func__, i, els_xri_cnt); 5268 - goto out_free_mem; 5269 - } 5270 - 5271 - sglq_entry->buff_type = GEN_BUFF_TYPE; 5272 - sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys); 5273 - if (sglq_entry->virt == NULL) { 5274 - kfree(sglq_entry); 5275 - printk(KERN_ERR "%s: failed to allocate mbuf.\n" 5276 - "Unloading driver.\n", __func__); 5277 - goto out_free_mem; 5278 - } 5279 - sglq_entry->sgl = sglq_entry->virt; 5280 - memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); 5281 - 5282 - /* The list order is used by later block SGL registraton */ 5283 - spin_lock_irq(&phba->hbalock); 5284 - sglq_entry->state = SGL_FREED; 5285 - list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list); 5286 - phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry; 5287 - phba->sli4_hba.total_sglq_bufs++; 5288 - spin_unlock_irq(&phba->hbalock); 5289 - } 5290 - return 0; 5291 - 5292 - out_free_mem: 5293 - kfree(phba->sli4_hba.lpfc_scsi_psb_array); 5294 - lpfc_free_sgl_list(phba); 5295 - return -ENOMEM; 5296 5073 } 5297 5074 5298 5075 /** ··· 7383 7320 phba->sli4_hba.u.if_type2.ERR2regaddr); 7384 7321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 7385 7322 "2890 Port error detected during port " 7386 - "reset(%d): port status reg 0x%x, " 7323 + "reset(%d): wait_tmo:%d ms, " 7324 + "port status reg 0x%x, " 7387 7325 "error 1=0x%x, error 2=0x%x\n", 7388 - num_resets, reg_data.word0, 7326 + num_resets, rdy_chk*10, 7327 + reg_data.word0, 7389 7328 phba->work_status[0], 7390 7329 phba->work_status[1]); 7391 7330 rc = -ENODEV; ··· 8759 8694 /* Release all the vports against this physical port */ 8760 8695 vports = lpfc_create_vport_work_array(phba); 8761 8696 if (vports != NULL) 8762 - for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) 8697 + for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 8698 + if (vports[i]->port_type == LPFC_PHYSICAL_PORT) 8699 + continue; 8763 8700 fc_vport_terminate(vports[i]->fc_vport); 8701 + } 8764 8702 lpfc_destroy_vport_work_array(phba, vports); 8765 8703 8766 8704 /* Remove FC host and then SCSI host with the physical port */ ··· 9183 9115 return 50; 9184 9116 else if (max_xri <= 1024) 9185 9117 return 100; 9186 - else 9118 + else if (max_xri <= 1536) 9187 9119 return 150; 9120 + else if (max_xri <= 2048) 9121 + return 200; 9122 + else 9123 + return 250; 9188 9124 } else 9189 9125 return 0; 9190 9126 } ··· 9527 9455 /* Release all the vports against this physical port */ 9528 9456 vports = lpfc_create_vport_work_array(phba); 9529 9457 if (vports != NULL) 9530 - for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) 9458 + for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 9459 + if (vports[i]->port_type == LPFC_PHYSICAL_PORT) 9460 + continue; 9531 9461 fc_vport_terminate(vports[i]->fc_vport); 9462 + } 9532 9463 lpfc_destroy_vport_work_array(phba, vports); 9533 9464 9534 9465 /* Remove FC host and then SCSI host with the physical port */
+9
drivers/scsi/lpfc/lpfc_nportdisc.c
··· 367 367 return 1; 368 368 } 369 369 370 + /* Check for Nport to NPort pt2pt protocol */ 370 371 if ((vport->fc_flag & FC_PT2PT) && 371 372 !(vport->fc_flag & FC_PT2PT_PLOGI)) { 373 + 372 374 /* rcv'ed PLOGI decides what our NPortId will be */ 373 375 vport->fc_myDID = icmd->un.rcvels.parmRo; 374 376 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); ··· 384 382 mempool_free(mbox, phba->mbox_mem_pool); 385 383 goto out; 386 384 } 385 + /* 386 + * For SLI4, the VFI/VPI are registered AFTER the 387 + * Nport with the higher WWPN sends us a PLOGI with 388 + * our assigned NPortId. 389 + */ 390 + if (phba->sli_rev == LPFC_SLI_REV4) 391 + lpfc_issue_reg_vfi(vport); 387 392 388 393 lpfc_can_disctmo(vport); 389 394 }
+276 -142
drivers/scsi/lpfc/lpfc_scsi.c
··· 399 399 num_rsrc_err = atomic_read(&phba->num_rsrc_err); 400 400 num_cmd_success = atomic_read(&phba->num_cmd_success); 401 401 402 + /* 403 + * The error and success command counters are global per 404 + * driver instance. If another handler has already 405 + * operated on this error event, just exit. 406 + */ 407 + if (num_rsrc_err == 0) 408 + return; 409 + 402 410 vports = lpfc_create_vport_work_array(phba); 403 411 if (vports != NULL) 404 412 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { ··· 696 688 rrq_empty = list_empty(&phba->active_rrq_list); 697 689 spin_unlock_irqrestore(&phba->hbalock, iflag); 698 690 if (ndlp) { 699 - lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1); 691 + lpfc_set_rrq_active(phba, ndlp, 692 + psb->cur_iocbq.sli4_lxritag, rxid, 1); 700 693 lpfc_sli4_abts_err_handler(phba, ndlp, axri); 701 694 } 702 695 lpfc_release_scsi_buf_s4(phba, psb); ··· 727 718 } 728 719 729 720 /** 730 - * lpfc_sli4_repost_scsi_sgl_list - Repsot the Scsi buffers sgl pages as block 721 + * lpfc_sli4_post_scsi_sgl_list - Psot blocks of scsi buffer sgls from a list 722 + * @phba: pointer to lpfc hba data structure. 723 + * @post_sblist: pointer to the scsi buffer list. 724 + * 725 + * This routine walks a list of scsi buffers that was passed in. It attempts 726 + * to construct blocks of scsi buffer sgls which contains contiguous xris and 727 + * uses the non-embedded SGL block post mailbox commands to post to the port. 728 + * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use 729 + * embedded SGL post mailbox command for posting. The @post_sblist passed in 730 + * must be local list, thus no lock is needed when manipulate the list. 731 + * 732 + * Returns: 0 = failure, non-zero number of successfully posted buffers. 733 + **/ 734 + int 735 + lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba *phba, 736 + struct list_head *post_sblist, int sb_count) 737 + { 738 + struct lpfc_scsi_buf *psb, *psb_next; 739 + int status; 740 + int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; 741 + dma_addr_t pdma_phys_bpl1; 742 + int last_xritag = NO_XRI; 743 + LIST_HEAD(prep_sblist); 744 + LIST_HEAD(blck_sblist); 745 + LIST_HEAD(scsi_sblist); 746 + 747 + /* sanity check */ 748 + if (sb_count <= 0) 749 + return -EINVAL; 750 + 751 + list_for_each_entry_safe(psb, psb_next, post_sblist, list) { 752 + list_del_init(&psb->list); 753 + block_cnt++; 754 + if ((last_xritag != NO_XRI) && 755 + (psb->cur_iocbq.sli4_xritag != last_xritag + 1)) { 756 + /* a hole in xri block, form a sgl posting block */ 757 + list_splice_init(&prep_sblist, &blck_sblist); 758 + post_cnt = block_cnt - 1; 759 + /* prepare list for next posting block */ 760 + list_add_tail(&psb->list, &prep_sblist); 761 + block_cnt = 1; 762 + } else { 763 + /* prepare list for next posting block */ 764 + list_add_tail(&psb->list, &prep_sblist); 765 + /* enough sgls for non-embed sgl mbox command */ 766 + if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { 767 + list_splice_init(&prep_sblist, &blck_sblist); 768 + post_cnt = block_cnt; 769 + block_cnt = 0; 770 + } 771 + } 772 + num_posting++; 773 + last_xritag = psb->cur_iocbq.sli4_xritag; 774 + 775 + /* end of repost sgl list condition for SCSI buffers */ 776 + if (num_posting == sb_count) { 777 + if (post_cnt == 0) { 778 + /* last sgl posting block */ 779 + list_splice_init(&prep_sblist, &blck_sblist); 780 + post_cnt = block_cnt; 781 + } else if (block_cnt == 1) { 782 + /* last single sgl with non-contiguous xri */ 783 + if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) 784 + pdma_phys_bpl1 = psb->dma_phys_bpl + 785 + SGL_PAGE_SIZE; 786 + else 787 + pdma_phys_bpl1 = 0; 788 + status = lpfc_sli4_post_sgl(phba, 789 + psb->dma_phys_bpl, 790 + pdma_phys_bpl1, 791 + psb->cur_iocbq.sli4_xritag); 792 + if (status) { 793 + /* failure, put on abort scsi list */ 794 + psb->exch_busy = 1; 795 + } else { 796 + /* success, put on SCSI buffer list */ 797 + psb->exch_busy = 0; 798 + psb->status = IOSTAT_SUCCESS; 799 + num_posted++; 800 + } 801 + /* success, put on SCSI buffer sgl list */ 802 + list_add_tail(&psb->list, &scsi_sblist); 803 + } 804 + } 805 + 806 + /* continue until a nembed page worth of sgls */ 807 + if (post_cnt == 0) 808 + continue; 809 + 810 + /* post block of SCSI buffer list sgls */ 811 + status = lpfc_sli4_post_scsi_sgl_block(phba, &blck_sblist, 812 + post_cnt); 813 + 814 + /* don't reset xirtag due to hole in xri block */ 815 + if (block_cnt == 0) 816 + last_xritag = NO_XRI; 817 + 818 + /* reset SCSI buffer post count for next round of posting */ 819 + post_cnt = 0; 820 + 821 + /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */ 822 + while (!list_empty(&blck_sblist)) { 823 + list_remove_head(&blck_sblist, psb, 824 + struct lpfc_scsi_buf, list); 825 + if (status) { 826 + /* failure, put on abort scsi list */ 827 + psb->exch_busy = 1; 828 + } else { 829 + /* success, put on SCSI buffer list */ 830 + psb->exch_busy = 0; 831 + psb->status = IOSTAT_SUCCESS; 832 + num_posted++; 833 + } 834 + list_add_tail(&psb->list, &scsi_sblist); 835 + } 836 + } 837 + /* Push SCSI buffers with sgl posted to the availble list */ 838 + while (!list_empty(&scsi_sblist)) { 839 + list_remove_head(&scsi_sblist, psb, 840 + struct lpfc_scsi_buf, list); 841 + lpfc_release_scsi_buf_s4(phba, psb); 842 + } 843 + return num_posted; 844 + } 845 + 846 + /** 847 + * lpfc_sli4_repost_scsi_sgl_list - Repsot all the allocated scsi buffer sgls 731 848 * @phba: pointer to lpfc hba data structure. 732 849 * 733 850 * This routine walks the list of scsi buffers that have been allocated and 734 - * repost them to the HBA by using SGL block post. This is needed after a 851 + * repost them to the port by using SGL block post. This is needed after a 735 852 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine 736 853 * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list 737 854 * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. ··· 867 732 int 868 733 lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) 869 734 { 870 - struct lpfc_scsi_buf *psb; 871 - int index, status, bcnt = 0, rcnt = 0, rc = 0; 872 - LIST_HEAD(sblist); 735 + LIST_HEAD(post_sblist); 736 + int num_posted, rc = 0; 873 737 874 - for (index = 0; index < phba->sli4_hba.scsi_xri_cnt; index++) { 875 - psb = phba->sli4_hba.lpfc_scsi_psb_array[index]; 876 - if (psb) { 877 - /* Remove from SCSI buffer list */ 878 - list_del(&psb->list); 879 - /* Add it to a local SCSI buffer list */ 880 - list_add_tail(&psb->list, &sblist); 881 - if (++rcnt == LPFC_NEMBED_MBOX_SGL_CNT) { 882 - bcnt = rcnt; 883 - rcnt = 0; 884 - } 885 - } else 886 - /* A hole present in the XRI array, need to skip */ 887 - bcnt = rcnt; 738 + /* get all SCSI buffers need to repost to a local list */ 739 + spin_lock(&phba->scsi_buf_list_lock); 740 + list_splice_init(&phba->lpfc_scsi_buf_list, &post_sblist); 741 + spin_unlock(&phba->scsi_buf_list_lock); 888 742 889 - if (index == phba->sli4_hba.scsi_xri_cnt - 1) 890 - /* End of XRI array for SCSI buffer, complete */ 891 - bcnt = rcnt; 892 - 893 - /* Continue until collect up to a nembed page worth of sgls */ 894 - if (bcnt == 0) 895 - continue; 896 - /* Now, post the SCSI buffer list sgls as a block */ 897 - if (!phba->sli4_hba.extents_in_use) 898 - status = lpfc_sli4_post_scsi_sgl_block(phba, 899 - &sblist, 900 - bcnt); 901 - else 902 - status = lpfc_sli4_post_scsi_sgl_blk_ext(phba, 903 - &sblist, 904 - bcnt); 905 - /* Reset SCSI buffer count for next round of posting */ 906 - bcnt = 0; 907 - while (!list_empty(&sblist)) { 908 - list_remove_head(&sblist, psb, struct lpfc_scsi_buf, 909 - list); 910 - if (status) { 911 - /* Put this back on the abort scsi list */ 912 - psb->exch_busy = 1; 913 - rc++; 914 - } else { 915 - psb->exch_busy = 0; 916 - psb->status = IOSTAT_SUCCESS; 917 - } 918 - /* Put it back into the SCSI buffer list */ 919 - lpfc_release_scsi_buf_s4(phba, psb); 920 - } 743 + /* post the list of scsi buffer sgls to port if available */ 744 + if (!list_empty(&post_sblist)) { 745 + num_posted = lpfc_sli4_post_scsi_sgl_list(phba, &post_sblist, 746 + phba->sli4_hba.scsi_xri_cnt); 747 + /* failed to post any scsi buffer, return error */ 748 + if (num_posted == 0) 749 + rc = -EIO; 921 750 } 922 751 return rc; 923 752 } ··· 891 792 * @vport: The virtual port for which this call being executed. 892 793 * @num_to_allocate: The requested number of buffers to allocate. 893 794 * 894 - * This routine allocates a scsi buffer for device with SLI-4 interface spec, 795 + * This routine allocates scsi buffers for device with SLI-4 interface spec, 895 796 * the scsi buffer contains all the necessary information needed to initiate 896 - * a SCSI I/O. 797 + * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put 798 + * them on a list, it post them to the port by using SGL block post. 897 799 * 898 800 * Return codes: 899 - * int - number of scsi buffers that were allocated. 801 + * int - number of scsi buffers that were allocated and posted. 900 802 * 0 = failure, less than num_to_alloc is a partial failure. 901 803 **/ 902 804 static int ··· 910 810 dma_addr_t pdma_phys_fcp_cmd; 911 811 dma_addr_t pdma_phys_fcp_rsp; 912 812 dma_addr_t pdma_phys_bpl, pdma_phys_bpl1; 913 - uint16_t iotag, last_xritag = NO_XRI, lxri = 0; 914 - int status = 0, index; 915 - int bcnt; 916 - int non_sequential_xri = 0; 917 - LIST_HEAD(sblist); 813 + uint16_t iotag, lxri = 0; 814 + int bcnt, num_posted; 815 + LIST_HEAD(prep_sblist); 816 + LIST_HEAD(post_sblist); 817 + LIST_HEAD(scsi_sblist); 918 818 919 819 for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { 920 820 psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); 921 821 if (!psb) 922 822 break; 923 - 924 823 /* 925 - * Get memory from the pci pool to map the virt space to pci bus 926 - * space for an I/O. The DMA buffer includes space for the 927 - * struct fcp_cmnd, struct fcp_rsp and the number of bde's 928 - * necessary to support the sg_tablesize. 824 + * Get memory from the pci pool to map the virt space to 825 + * pci bus space for an I/O. The DMA buffer includes space 826 + * for the struct fcp_cmnd, struct fcp_rsp and the number 827 + * of bde's necessary to support the sg_tablesize. 929 828 */ 930 829 psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, 931 830 GFP_KERNEL, &psb->dma_handle); ··· 932 833 kfree(psb); 933 834 break; 934 835 } 935 - 936 - /* Initialize virtual ptrs to dma_buf region. */ 937 836 memset(psb->data, 0, phba->cfg_sg_dma_buf_size); 938 837 939 838 /* Allocate iotag for psb->cur_iocbq. */ ··· 952 855 } 953 856 psb->cur_iocbq.sli4_lxritag = lxri; 954 857 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; 955 - if (last_xritag != NO_XRI 956 - && psb->cur_iocbq.sli4_xritag != (last_xritag+1)) { 957 - non_sequential_xri = 1; 958 - } else 959 - list_add_tail(&psb->list, &sblist); 960 - last_xritag = psb->cur_iocbq.sli4_xritag; 961 - 962 - index = phba->sli4_hba.scsi_xri_cnt++; 963 858 psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; 964 - 965 859 psb->fcp_bpl = psb->data; 966 860 psb->fcp_cmnd = (psb->data + phba->cfg_sg_dma_buf_size) 967 861 - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); ··· 968 880 pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); 969 881 970 882 /* 971 - * The first two bdes are the FCP_CMD and FCP_RSP. The balance 972 - * are sg list bdes. Initialize the first two and leave the 973 - * rest for queuecommand. 883 + * The first two bdes are the FCP_CMD and FCP_RSP. 884 + * The balance are sg list bdes. Initialize the 885 + * first two and leave the rest for queuecommand. 974 886 */ 975 887 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); 976 888 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); ··· 1005 917 iocb->ulpBdeCount = 1; 1006 918 iocb->ulpLe = 1; 1007 919 iocb->ulpClass = CLASS3; 1008 - psb->cur_iocbq.context1 = psb; 920 + psb->cur_iocbq.context1 = psb; 1009 921 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) 1010 922 pdma_phys_bpl1 = pdma_phys_bpl + SGL_PAGE_SIZE; 1011 923 else 1012 924 pdma_phys_bpl1 = 0; 1013 925 psb->dma_phys_bpl = pdma_phys_bpl; 1014 - phba->sli4_hba.lpfc_scsi_psb_array[index] = psb; 1015 - if (non_sequential_xri) { 1016 - status = lpfc_sli4_post_sgl(phba, pdma_phys_bpl, 1017 - pdma_phys_bpl1, 1018 - psb->cur_iocbq.sli4_xritag); 1019 - if (status) { 1020 - /* Put this back on the abort scsi list */ 1021 - psb->exch_busy = 1; 1022 - } else { 1023 - psb->exch_busy = 0; 1024 - psb->status = IOSTAT_SUCCESS; 1025 - } 1026 - /* Put it back into the SCSI buffer list */ 1027 - lpfc_release_scsi_buf_s4(phba, psb); 1028 - break; 1029 - } 1030 - } 1031 - if (bcnt) { 1032 - if (!phba->sli4_hba.extents_in_use) 1033 - status = lpfc_sli4_post_scsi_sgl_block(phba, 1034 - &sblist, 1035 - bcnt); 1036 - else 1037 - status = lpfc_sli4_post_scsi_sgl_blk_ext(phba, 1038 - &sblist, 1039 - bcnt); 1040 926 1041 - if (status) { 1042 - lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, 1043 - "3021 SCSI SGL post error %d\n", 1044 - status); 1045 - bcnt = 0; 1046 - } 1047 - /* Reset SCSI buffer count for next round of posting */ 1048 - while (!list_empty(&sblist)) { 1049 - list_remove_head(&sblist, psb, struct lpfc_scsi_buf, 1050 - list); 1051 - if (status) { 1052 - /* Put this back on the abort scsi list */ 1053 - psb->exch_busy = 1; 1054 - } else { 1055 - psb->exch_busy = 0; 1056 - psb->status = IOSTAT_SUCCESS; 1057 - } 1058 - /* Put it back into the SCSI buffer list */ 1059 - lpfc_release_scsi_buf_s4(phba, psb); 1060 - } 927 + /* add the scsi buffer to a post list */ 928 + list_add_tail(&psb->list, &post_sblist); 929 + spin_lock_irq(&phba->scsi_buf_list_lock); 930 + phba->sli4_hba.scsi_xri_cnt++; 931 + spin_unlock_irq(&phba->scsi_buf_list_lock); 1061 932 } 933 + lpfc_printf_log(phba, KERN_INFO, LOG_BG, 934 + "3021 Allocate %d out of %d requested new SCSI " 935 + "buffers\n", bcnt, num_to_alloc); 1062 936 1063 - return bcnt + non_sequential_xri; 937 + /* post the list of scsi buffer sgls to port if available */ 938 + if (!list_empty(&post_sblist)) 939 + num_posted = lpfc_sli4_post_scsi_sgl_list(phba, 940 + &post_sblist, bcnt); 941 + else 942 + num_posted = 0; 943 + 944 + return num_posted; 1064 945 } 1065 946 1066 947 /** ··· 1100 1043 list_for_each_entry(lpfc_cmd, &phba->lpfc_scsi_buf_list, 1101 1044 list) { 1102 1045 if (lpfc_test_rrq_active(phba, ndlp, 1103 - lpfc_cmd->cur_iocbq.sli4_xritag)) 1046 + lpfc_cmd->cur_iocbq.sli4_lxritag)) 1104 1047 continue; 1105 1048 list_del(&lpfc_cmd->list); 1106 1049 found = 1; ··· 1954 1897 dma_addr_t physaddr; 1955 1898 int i = 0, num_bde = 0, status; 1956 1899 int datadir = sc->sc_data_direction; 1900 + #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1957 1901 uint32_t rc; 1902 + #endif 1958 1903 uint32_t checking = 1; 1959 1904 uint32_t reftag; 1960 1905 unsigned blksize; ··· 2093 2034 int datadir = sc->sc_data_direction; 2094 2035 unsigned char pgdone = 0, alldone = 0; 2095 2036 unsigned blksize; 2037 + #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 2096 2038 uint32_t rc; 2039 + #endif 2097 2040 uint32_t checking = 1; 2098 2041 uint32_t reftag; 2099 2042 uint8_t txop, rxop; ··· 2314 2253 uint32_t reftag; 2315 2254 unsigned blksize; 2316 2255 uint8_t txop, rxop; 2256 + #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 2317 2257 uint32_t rc; 2258 + #endif 2318 2259 uint32_t checking = 1; 2319 2260 uint32_t dma_len; 2320 2261 uint32_t dma_offset = 0; ··· 2446 2383 uint32_t reftag; 2447 2384 uint8_t txop, rxop; 2448 2385 uint32_t dma_len; 2386 + #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 2449 2387 uint32_t rc; 2388 + #endif 2450 2389 uint32_t checking = 1; 2451 2390 uint32_t dma_offset = 0; 2452 2391 int num_sge = 0; ··· 3669 3604 logit = LOG_FCP | LOG_FCP_UNDER; 3670 3605 lpfc_printf_vlog(vport, KERN_WARNING, logit, 3671 3606 "9030 FCP cmd x%x failed <%d/%d> " 3672 - "status: x%x result: x%x Data: x%x x%x\n", 3607 + "status: x%x result: x%x " 3608 + "sid: x%x did: x%x oxid: x%x " 3609 + "Data: x%x x%x\n", 3673 3610 cmd->cmnd[0], 3674 3611 cmd->device ? cmd->device->id : 0xffff, 3675 3612 cmd->device ? cmd->device->lun : 0xffff, 3676 3613 lpfc_cmd->status, lpfc_cmd->result, 3614 + vport->fc_myDID, pnode->nlp_DID, 3615 + phba->sli_rev == LPFC_SLI_REV4 ? 3616 + lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, 3677 3617 pIocbOut->iocb.ulpContext, 3678 3618 lpfc_cmd->cur_iocbq.iocb.ulpIoTag); 3679 3619 ··· 3759 3689 * ABTS we cannot generate and RRQ. 3760 3690 */ 3761 3691 lpfc_set_rrq_active(phba, pnode, 3762 - lpfc_cmd->cur_iocbq.sli4_xritag, 3763 - 0, 0); 3692 + lpfc_cmd->cur_iocbq.sli4_lxritag, 3693 + 0, 0); 3764 3694 } 3765 3695 /* else: fall through */ 3766 3696 default: ··· 4418 4348 ret = fc_block_scsi_eh(cmnd); 4419 4349 if (ret) 4420 4350 return ret; 4351 + 4352 + spin_lock_irq(&phba->hbalock); 4353 + /* driver queued commands are in process of being flushed */ 4354 + if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { 4355 + spin_unlock_irq(&phba->hbalock); 4356 + lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, 4357 + "3168 SCSI Layer abort requested I/O has been " 4358 + "flushed by LLD.\n"); 4359 + return FAILED; 4360 + } 4361 + 4421 4362 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; 4422 4363 if (!lpfc_cmd) { 4364 + spin_unlock_irq(&phba->hbalock); 4423 4365 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, 4424 4366 "2873 SCSI Layer I/O Abort Request IO CMPL Status " 4425 4367 "x%x ID %d LUN %d\n", ··· 4439 4357 return SUCCESS; 4440 4358 } 4441 4359 4360 + iocb = &lpfc_cmd->cur_iocbq; 4361 + /* the command is in process of being cancelled */ 4362 + if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { 4363 + spin_unlock_irq(&phba->hbalock); 4364 + lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, 4365 + "3169 SCSI Layer abort requested I/O has been " 4366 + "cancelled by LLD.\n"); 4367 + return FAILED; 4368 + } 4442 4369 /* 4443 4370 * If pCmd field of the corresponding lpfc_scsi_buf structure 4444 4371 * points to a different SCSI command, then the driver has 4445 4372 * already completed this command, but the midlayer did not 4446 - * see the completion before the eh fired. Just return 4447 - * SUCCESS. 4373 + * see the completion before the eh fired. Just return SUCCESS. 4448 4374 */ 4449 - iocb = &lpfc_cmd->cur_iocbq; 4450 - if (lpfc_cmd->pCmd != cmnd) 4451 - goto out; 4375 + if (lpfc_cmd->pCmd != cmnd) { 4376 + lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, 4377 + "3170 SCSI Layer abort requested I/O has been " 4378 + "completed by LLD.\n"); 4379 + goto out_unlock; 4380 + } 4452 4381 4453 4382 BUG_ON(iocb->context1 != lpfc_cmd); 4454 4383 4455 - abtsiocb = lpfc_sli_get_iocbq(phba); 4384 + abtsiocb = __lpfc_sli_get_iocbq(phba); 4456 4385 if (abtsiocb == NULL) { 4457 4386 ret = FAILED; 4458 - goto out; 4387 + goto out_unlock; 4459 4388 } 4460 4389 4461 4390 /* ··· 4498 4405 4499 4406 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; 4500 4407 abtsiocb->vport = vport; 4408 + /* no longer need the lock after this point */ 4409 + spin_unlock_irq(&phba->hbalock); 4410 + 4501 4411 if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) == 4502 4412 IOCB_ERROR) { 4503 4413 lpfc_sli_release_iocbq(phba, abtsiocb); ··· 4517 4421 wait_event_timeout(waitq, 4518 4422 (lpfc_cmd->pCmd != cmnd), 4519 4423 (2*vport->cfg_devloss_tmo*HZ)); 4520 - 4521 - spin_lock_irq(shost->host_lock); 4522 4424 lpfc_cmd->waitq = NULL; 4523 - spin_unlock_irq(shost->host_lock); 4524 4425 4525 4426 if (lpfc_cmd->pCmd == cmnd) { 4526 4427 ret = FAILED; ··· 4527 4434 "LUN %d\n", 4528 4435 ret, cmnd->device->id, cmnd->device->lun); 4529 4436 } 4437 + goto out; 4530 4438 4531 - out: 4439 + out_unlock: 4440 + spin_unlock_irq(&phba->hbalock); 4441 + out: 4532 4442 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, 4533 4443 "0749 SCSI Layer I/O Abort Request Status x%x ID %d " 4534 4444 "LUN %d\n", ret, cmnd->device->id, ··· 4959 4863 } 4960 4864 4961 4865 /** 4866 + * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt 4867 + * @cmnd: Pointer to scsi_cmnd data structure. 4868 + * 4869 + * This routine does host reset to the adaptor port. It brings the HBA 4870 + * offline, performs a board restart, and then brings the board back online. 4871 + * The lpfc_offline calls lpfc_sli_hba_down which will abort and local 4872 + * reject all outstanding SCSI commands to the host and error returned 4873 + * back to SCSI mid-level. As this will be SCSI mid-level's last resort 4874 + * of error handling, it will only return error if resetting of the adapter 4875 + * is not successful; in all other cases, will return success. 4876 + * 4877 + * Return code : 4878 + * 0x2003 - Error 4879 + * 0x2002 - Success 4880 + **/ 4881 + static int 4882 + lpfc_host_reset_handler(struct scsi_cmnd *cmnd) 4883 + { 4884 + struct Scsi_Host *shost = cmnd->device->host; 4885 + struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 4886 + struct lpfc_hba *phba = vport->phba; 4887 + int rc, ret = SUCCESS; 4888 + 4889 + lpfc_offline_prep(phba); 4890 + lpfc_offline(phba); 4891 + rc = lpfc_sli_brdrestart(phba); 4892 + if (rc) 4893 + ret = FAILED; 4894 + lpfc_online(phba); 4895 + lpfc_unblock_mgmt_io(phba); 4896 + 4897 + lpfc_printf_log(phba, KERN_ERR, LOG_FCP, 4898 + "3172 SCSI layer issued Host Reset Data: x%x\n", ret); 4899 + return ret; 4900 + } 4901 + 4902 + /** 4962 4903 * lpfc_slave_alloc - scsi_host_template slave_alloc entry point 4963 4904 * @sdev: Pointer to scsi_device. 4964 4905 * ··· 5127 4994 .eh_device_reset_handler = lpfc_device_reset_handler, 5128 4995 .eh_target_reset_handler = lpfc_target_reset_handler, 5129 4996 .eh_bus_reset_handler = lpfc_bus_reset_handler, 4997 + .eh_host_reset_handler = lpfc_host_reset_handler, 5130 4998 .slave_alloc = lpfc_slave_alloc, 5131 4999 .slave_configure = lpfc_slave_configure, 5132 5000 .slave_destroy = lpfc_slave_destroy,
+325 -460
drivers/scsi/lpfc/lpfc_sli.c
··· 67 67 struct hbq_dmabuf *); 68 68 static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, 69 69 struct lpfc_cqe *); 70 + static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *, 71 + int); 70 72 71 73 static IOCB_t * 72 74 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) ··· 502 500 * allocation is successful, it returns pointer to the newly 503 501 * allocated iocb object else it returns NULL. 504 502 **/ 505 - static struct lpfc_iocbq * 503 + struct lpfc_iocbq * 506 504 __lpfc_sli_get_iocbq(struct lpfc_hba *phba) 507 505 { 508 506 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; ··· 877 875 } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && 878 876 !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) 879 877 ndlp = piocbq->context_un.ndlp; 878 + else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) && 879 + (piocbq->iocb_flag & LPFC_IO_LIBDFC)) 880 + ndlp = piocbq->context_un.ndlp; 880 881 else 881 882 ndlp = piocbq->context1; 882 883 ··· 888 883 while (!found) { 889 884 if (!sglq) 890 885 return NULL; 891 - if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) { 886 + if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { 892 887 /* This xri has an rrq outstanding for this DID. 893 888 * put it back in the list and get another xri. 894 889 */ ··· 1262 1257 struct lpfc_iocbq *piocb) 1263 1258 { 1264 1259 list_add_tail(&piocb->list, &pring->txcmplq); 1265 - piocb->iocb_flag |= LPFC_IO_ON_Q; 1260 + piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; 1266 1261 pring->txcmplq_cnt++; 1267 1262 if (pring->txcmplq_cnt > pring->txcmplq_max) 1268 1263 pring->txcmplq_max = pring->txcmplq_cnt; ··· 2561 2556 if (iotag != 0 && iotag <= phba->sli.last_iotag) { 2562 2557 cmd_iocb = phba->sli.iocbq_lookup[iotag]; 2563 2558 list_del_init(&cmd_iocb->list); 2564 - if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { 2559 + if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { 2565 2560 pring->txcmplq_cnt--; 2566 - cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; 2561 + cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; 2567 2562 } 2568 2563 return cmd_iocb; 2569 2564 } ··· 2596 2591 2597 2592 if (iotag != 0 && iotag <= phba->sli.last_iotag) { 2598 2593 cmd_iocb = phba->sli.iocbq_lookup[iotag]; 2599 - list_del_init(&cmd_iocb->list); 2600 - if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { 2601 - cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; 2594 + if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { 2595 + /* remove from txcmpl queue list */ 2596 + list_del_init(&cmd_iocb->list); 2597 + cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; 2602 2598 pring->txcmplq_cnt--; 2599 + return cmd_iocb; 2603 2600 } 2604 - return cmd_iocb; 2605 2601 } 2606 - 2607 2602 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 2608 2603 "0372 iotag x%x is out off range: max iotag (x%x)\n", 2609 2604 iotag, phba->sli.last_iotag); ··· 3471 3466 /* Retrieve everything on the txcmplq */ 3472 3467 list_splice_init(&pring->txcmplq, &txcmplq); 3473 3468 pring->txcmplq_cnt = 0; 3469 + 3470 + /* Indicate the I/O queues are flushed */ 3471 + phba->hba_flag |= HBA_FCP_IOQ_FLUSH; 3474 3472 spin_unlock_irq(&phba->hbalock); 3475 3473 3476 3474 /* Flush the txq */ ··· 3885 3877 { 3886 3878 struct lpfc_sli *psli = &phba->sli; 3887 3879 uint16_t cfg_value; 3880 + int rc; 3888 3881 3889 3882 /* Reset HBA */ 3890 3883 lpfc_printf_log(phba, KERN_INFO, LOG_SLI, ··· 3914 3905 3915 3906 /* Perform FCoE PCI function reset */ 3916 3907 lpfc_sli4_queue_destroy(phba); 3917 - lpfc_pci_function_reset(phba); 3908 + rc = lpfc_pci_function_reset(phba); 3918 3909 3919 3910 /* Restore PCI cmd register */ 3920 3911 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); 3921 3912 3922 - return 0; 3913 + return rc; 3923 3914 } 3924 3915 3925 3916 /** ··· 4011 4002 { 4012 4003 struct lpfc_sli *psli = &phba->sli; 4013 4004 uint32_t hba_aer_enabled; 4005 + int rc; 4014 4006 4015 4007 /* Restart HBA */ 4016 4008 lpfc_printf_log(phba, KERN_INFO, LOG_SLI, ··· 4021 4011 /* Take PCIe device Advanced Error Reporting (AER) state */ 4022 4012 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; 4023 4013 4024 - lpfc_sli4_brdreset(phba); 4014 + rc = lpfc_sli4_brdreset(phba); 4025 4015 4026 4016 spin_lock_irq(&phba->hbalock); 4027 4017 phba->pport->stopped = 0; ··· 4038 4028 4039 4029 lpfc_hba_down_post(phba); 4040 4030 4041 - return 0; 4031 + return rc; 4042 4032 } 4043 4033 4044 4034 /** ··· 4977 4967 &rsrc_info->u.rsp); 4978 4968 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, 4979 4969 &rsrc_info->u.rsp); 4980 - err_exit: 4970 + 4971 + lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 4972 + "3162 Retrieved extents type-%d from port: count:%d, " 4973 + "size:%d\n", type, *extnt_count, *extnt_size); 4974 + 4975 + err_exit: 4981 4976 mempool_free(mbox, phba->mbox_mem_pool); 4982 4977 return rc; 4983 4978 } ··· 5066 5051 * 0: if successful 5067 5052 **/ 5068 5053 static int 5069 - lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t *extnt_cnt, 5054 + lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt, 5070 5055 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) 5071 5056 { 5072 5057 int rc = 0; ··· 5075 5060 uint32_t alloc_len, mbox_tmo; 5076 5061 5077 5062 /* Calculate the total requested length of the dma memory */ 5078 - req_len = *extnt_cnt * sizeof(uint16_t); 5063 + req_len = extnt_cnt * sizeof(uint16_t); 5079 5064 5080 5065 /* 5081 5066 * Calculate the size of an embedded mailbox. The uint32_t ··· 5090 5075 */ 5091 5076 *emb = LPFC_SLI4_MBX_EMBED; 5092 5077 if (req_len > emb_len) { 5093 - req_len = *extnt_cnt * sizeof(uint16_t) + 5078 + req_len = extnt_cnt * sizeof(uint16_t) + 5094 5079 sizeof(union lpfc_sli4_cfg_shdr) + 5095 5080 sizeof(uint32_t); 5096 5081 *emb = LPFC_SLI4_MBX_NEMBED; ··· 5106 5091 "size (x%x)\n", alloc_len, req_len); 5107 5092 return -ENOMEM; 5108 5093 } 5109 - rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, *extnt_cnt, type, *emb); 5094 + rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); 5110 5095 if (unlikely(rc)) 5111 5096 return -EIO; 5112 5097 ··· 5164 5149 return -ENOMEM; 5165 5150 } 5166 5151 5167 - lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT, 5168 - "2903 Available Resource Extents " 5169 - "for resource type 0x%x: Count: 0x%x, " 5170 - "Size 0x%x\n", type, rsrc_cnt, 5171 - rsrc_size); 5152 + lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, 5153 + "2903 Post resource extents type-0x%x: " 5154 + "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); 5172 5155 5173 5156 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 5174 5157 if (!mbox) 5175 5158 return -ENOMEM; 5176 5159 5177 - rc = lpfc_sli4_cfg_post_extnts(phba, &rsrc_cnt, type, &emb, mbox); 5160 + rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); 5178 5161 if (unlikely(rc)) { 5179 5162 rc = -EIO; 5180 5163 goto err_exit; ··· 5263 5250 rc = -ENOMEM; 5264 5251 goto err_exit; 5265 5252 } 5253 + phba->sli4_hba.max_cfg_param.xri_used = 0; 5266 5254 phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * 5267 5255 sizeof(uint16_t), 5268 5256 GFP_KERNEL); ··· 5434 5420 case LPFC_RSC_TYPE_FCOE_XRI: 5435 5421 kfree(phba->sli4_hba.xri_bmask); 5436 5422 kfree(phba->sli4_hba.xri_ids); 5437 - bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); 5438 5423 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, 5439 5424 &phba->sli4_hba.lpfc_xri_blk_list, list) { 5440 5425 list_del_init(&rsrc_blk->list); ··· 5625 5612 goto free_vpi_ids; 5626 5613 } 5627 5614 phba->sli4_hba.max_cfg_param.xri_used = 0; 5628 - phba->sli4_hba.xri_count = 0; 5629 5615 phba->sli4_hba.xri_ids = kzalloc(count * 5630 5616 sizeof(uint16_t), 5631 5617 GFP_KERNEL); ··· 5706 5694 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); 5707 5695 kfree(phba->sli4_hba.xri_bmask); 5708 5696 kfree(phba->sli4_hba.xri_ids); 5709 - bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); 5710 5697 kfree(phba->sli4_hba.vfi_bmask); 5711 5698 kfree(phba->sli4_hba.vfi_ids); 5712 5699 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); ··· 5864 5853 } 5865 5854 5866 5855 /** 5856 + * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block 5857 + * @phba: pointer to lpfc hba data structure. 5858 + * 5859 + * This routine walks the list of els buffers that have been allocated and 5860 + * repost them to the port by using SGL block post. This is needed after a 5861 + * pci_function_reset/warm_start or start. It attempts to construct blocks 5862 + * of els buffer sgls which contains contiguous xris and uses the non-embedded 5863 + * SGL block post mailbox commands to post them to the port. For single els 5864 + * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post 5865 + * mailbox command for posting. 5866 + * 5867 + * Returns: 0 = success, non-zero failure. 5868 + **/ 5869 + static int 5870 + lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) 5871 + { 5872 + struct lpfc_sglq *sglq_entry = NULL; 5873 + struct lpfc_sglq *sglq_entry_next = NULL; 5874 + struct lpfc_sglq *sglq_entry_first = NULL; 5875 + int status, post_cnt = 0, num_posted = 0, block_cnt = 0; 5876 + int last_xritag = NO_XRI; 5877 + LIST_HEAD(prep_sgl_list); 5878 + LIST_HEAD(blck_sgl_list); 5879 + LIST_HEAD(allc_sgl_list); 5880 + LIST_HEAD(post_sgl_list); 5881 + LIST_HEAD(free_sgl_list); 5882 + 5883 + spin_lock(&phba->hbalock); 5884 + list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); 5885 + spin_unlock(&phba->hbalock); 5886 + 5887 + list_for_each_entry_safe(sglq_entry, sglq_entry_next, 5888 + &allc_sgl_list, list) { 5889 + list_del_init(&sglq_entry->list); 5890 + block_cnt++; 5891 + if ((last_xritag != NO_XRI) && 5892 + (sglq_entry->sli4_xritag != last_xritag + 1)) { 5893 + /* a hole in xri block, form a sgl posting block */ 5894 + list_splice_init(&prep_sgl_list, &blck_sgl_list); 5895 + post_cnt = block_cnt - 1; 5896 + /* prepare list for next posting block */ 5897 + list_add_tail(&sglq_entry->list, &prep_sgl_list); 5898 + block_cnt = 1; 5899 + } else { 5900 + /* prepare list for next posting block */ 5901 + list_add_tail(&sglq_entry->list, &prep_sgl_list); 5902 + /* enough sgls for non-embed sgl mbox command */ 5903 + if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { 5904 + list_splice_init(&prep_sgl_list, 5905 + &blck_sgl_list); 5906 + post_cnt = block_cnt; 5907 + block_cnt = 0; 5908 + } 5909 + } 5910 + num_posted++; 5911 + 5912 + /* keep track of last sgl's xritag */ 5913 + last_xritag = sglq_entry->sli4_xritag; 5914 + 5915 + /* end of repost sgl list condition for els buffers */ 5916 + if (num_posted == phba->sli4_hba.els_xri_cnt) { 5917 + if (post_cnt == 0) { 5918 + list_splice_init(&prep_sgl_list, 5919 + &blck_sgl_list); 5920 + post_cnt = block_cnt; 5921 + } else if (block_cnt == 1) { 5922 + status = lpfc_sli4_post_sgl(phba, 5923 + sglq_entry->phys, 0, 5924 + sglq_entry->sli4_xritag); 5925 + if (!status) { 5926 + /* successful, put sgl to posted list */ 5927 + list_add_tail(&sglq_entry->list, 5928 + &post_sgl_list); 5929 + } else { 5930 + /* Failure, put sgl to free list */ 5931 + lpfc_printf_log(phba, KERN_WARNING, 5932 + LOG_SLI, 5933 + "3159 Failed to post els " 5934 + "sgl, xritag:x%x\n", 5935 + sglq_entry->sli4_xritag); 5936 + list_add_tail(&sglq_entry->list, 5937 + &free_sgl_list); 5938 + spin_lock_irq(&phba->hbalock); 5939 + phba->sli4_hba.els_xri_cnt--; 5940 + spin_unlock_irq(&phba->hbalock); 5941 + } 5942 + } 5943 + } 5944 + 5945 + /* continue until a nembed page worth of sgls */ 5946 + if (post_cnt == 0) 5947 + continue; 5948 + 5949 + /* post the els buffer list sgls as a block */ 5950 + status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, 5951 + post_cnt); 5952 + 5953 + if (!status) { 5954 + /* success, put sgl list to posted sgl list */ 5955 + list_splice_init(&blck_sgl_list, &post_sgl_list); 5956 + } else { 5957 + /* Failure, put sgl list to free sgl list */ 5958 + sglq_entry_first = list_first_entry(&blck_sgl_list, 5959 + struct lpfc_sglq, 5960 + list); 5961 + lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, 5962 + "3160 Failed to post els sgl-list, " 5963 + "xritag:x%x-x%x\n", 5964 + sglq_entry_first->sli4_xritag, 5965 + (sglq_entry_first->sli4_xritag + 5966 + post_cnt - 1)); 5967 + list_splice_init(&blck_sgl_list, &free_sgl_list); 5968 + spin_lock_irq(&phba->hbalock); 5969 + phba->sli4_hba.els_xri_cnt -= post_cnt; 5970 + spin_unlock_irq(&phba->hbalock); 5971 + } 5972 + 5973 + /* don't reset xirtag due to hole in xri block */ 5974 + if (block_cnt == 0) 5975 + last_xritag = NO_XRI; 5976 + 5977 + /* reset els sgl post count for next round of posting */ 5978 + post_cnt = 0; 5979 + } 5980 + 5981 + /* free the els sgls failed to post */ 5982 + lpfc_free_sgl_list(phba, &free_sgl_list); 5983 + 5984 + /* push els sgls posted to the availble list */ 5985 + if (!list_empty(&post_sgl_list)) { 5986 + spin_lock(&phba->hbalock); 5987 + list_splice_init(&post_sgl_list, 5988 + &phba->sli4_hba.lpfc_sgl_list); 5989 + spin_unlock(&phba->hbalock); 5990 + } else { 5991 + lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 5992 + "3161 Failure to post els sgl to port.\n"); 5993 + return -EIO; 5994 + } 5995 + return 0; 5996 + } 5997 + 5998 + /** 5867 5999 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function 5868 6000 * @phba: Pointer to HBA context object. 5869 6001 * ··· 6076 5922 phba->hba_flag |= HBA_FIP_SUPPORT; 6077 5923 else 6078 5924 phba->hba_flag &= ~HBA_FIP_SUPPORT; 5925 + 5926 + phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; 6079 5927 6080 5928 if (phba->sli_rev != LPFC_SLI_REV4) { 6081 5929 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, ··· 6219 6063 "rc = x%x\n", rc); 6220 6064 goto out_free_mbox; 6221 6065 } 6222 - /* update physical xri mappings in the scsi buffers */ 6223 - lpfc_scsi_buf_update(phba); 6224 6066 6225 6067 /* Read the port's service parameters. */ 6226 6068 rc = lpfc_read_sparam(phba, mboxq, vport->vpi); ··· 6259 6105 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); 6260 6106 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); 6261 6107 6262 - /* Register SGL pool to the device using non-embedded mailbox command */ 6263 - if (!phba->sli4_hba.extents_in_use) { 6264 - rc = lpfc_sli4_post_els_sgl_list(phba); 6265 - if (unlikely(rc)) { 6266 - lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, 6267 - "0582 Error %d during els sgl post " 6268 - "operation\n", rc); 6269 - rc = -ENODEV; 6270 - goto out_free_mbox; 6271 - } 6272 - } else { 6273 - rc = lpfc_sli4_post_els_sgl_list_ext(phba); 6274 - if (unlikely(rc)) { 6275 - lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, 6276 - "2560 Error %d during els sgl post " 6277 - "operation\n", rc); 6278 - rc = -ENODEV; 6279 - goto out_free_mbox; 6280 - } 6108 + /* update host els and scsi xri-sgl sizes and mappings */ 6109 + rc = lpfc_sli4_xri_sgl_update(phba); 6110 + if (unlikely(rc)) { 6111 + lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, 6112 + "1400 Failed to update xri-sgl size and " 6113 + "mapping: %d\n", rc); 6114 + goto out_free_mbox; 6281 6115 } 6282 6116 6283 - /* Register SCSI SGL pool to the device */ 6117 + /* register the els sgl pool to the port */ 6118 + rc = lpfc_sli4_repost_els_sgl_list(phba); 6119 + if (unlikely(rc)) { 6120 + lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, 6121 + "0582 Error %d during els sgl post " 6122 + "operation\n", rc); 6123 + rc = -ENODEV; 6124 + goto out_free_mbox; 6125 + } 6126 + 6127 + /* register the allocated scsi sgl pool to the port */ 6284 6128 rc = lpfc_sli4_repost_scsi_sgl_list(phba); 6285 6129 if (unlikely(rc)) { 6286 6130 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, ··· 7212 7060 if (rc != MBX_SUCCESS) 7213 7061 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, 7214 7062 "(%d):2541 Mailbox command x%x " 7215 - "(x%x/x%x) cannot issue Data: " 7216 - "x%x x%x\n", 7063 + "(x%x/x%x) failure: " 7064 + "mqe_sta: x%x mcqe_sta: x%x/x%x " 7065 + "Data: x%x x%x\n,", 7217 7066 mboxq->vport ? mboxq->vport->vpi : 0, 7218 7067 mboxq->u.mb.mbxCommand, 7219 7068 lpfc_sli_config_mbox_subsys_get(phba, 7220 7069 mboxq), 7221 7070 lpfc_sli_config_mbox_opcode_get(phba, 7222 7071 mboxq), 7072 + bf_get(lpfc_mqe_status, &mboxq->u.mqe), 7073 + bf_get(lpfc_mcqe_status, &mboxq->mcqe), 7074 + bf_get(lpfc_mcqe_ext_status, 7075 + &mboxq->mcqe), 7223 7076 psli->sli_flag, flag); 7224 7077 return rc; 7225 7078 } else if (flag == MBX_POLL) { ··· 7243 7086 /* Successfully blocked, now issue sync mbox cmd */ 7244 7087 rc = lpfc_sli4_post_sync_mbox(phba, mboxq); 7245 7088 if (rc != MBX_SUCCESS) 7246 - lpfc_printf_log(phba, KERN_ERR, 7089 + lpfc_printf_log(phba, KERN_WARNING, 7247 7090 LOG_MBOX | LOG_SLI, 7248 - "(%d):2597 Mailbox command " 7249 - "x%x (x%x/x%x) cannot issue " 7250 - "Data: x%x x%x\n", 7251 - mboxq->vport ? 7252 - mboxq->vport->vpi : 0, 7091 + "(%d):2597 Sync Mailbox command " 7092 + "x%x (x%x/x%x) failure: " 7093 + "mqe_sta: x%x mcqe_sta: x%x/x%x " 7094 + "Data: x%x x%x\n,", 7095 + mboxq->vport ? mboxq->vport->vpi : 0, 7253 7096 mboxq->u.mb.mbxCommand, 7254 7097 lpfc_sli_config_mbox_subsys_get(phba, 7255 7098 mboxq), 7256 7099 lpfc_sli_config_mbox_opcode_get(phba, 7257 7100 mboxq), 7101 + bf_get(lpfc_mqe_status, &mboxq->u.mqe), 7102 + bf_get(lpfc_mcqe_status, &mboxq->mcqe), 7103 + bf_get(lpfc_mcqe_ext_status, 7104 + &mboxq->mcqe), 7258 7105 psli->sli_flag, flag); 7259 7106 /* Unblock the async mailbox posting afterward */ 7260 7107 lpfc_sli4_async_mbox_unblock(phba); ··· 7873 7712 7874 7713 switch (iocbq->iocb.ulpCommand) { 7875 7714 case CMD_ELS_REQUEST64_CR: 7876 - ndlp = (struct lpfc_nodelist *)iocbq->context1; 7715 + if (iocbq->iocb_flag & LPFC_IO_LIBDFC) 7716 + ndlp = iocbq->context_un.ndlp; 7717 + else 7718 + ndlp = (struct lpfc_nodelist *)iocbq->context1; 7877 7719 if (!iocbq->iocb.ulpLe) { 7878 7720 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 7879 7721 "2007 Only Limited Edition cmd Format" ··· 7915 7751 bf_set(els_req64_sp, &wqe->els_req, 1); 7916 7752 bf_set(els_req64_sid, &wqe->els_req, 7917 7753 iocbq->vport->fc_myDID); 7754 + if ((*pcmd == ELS_CMD_FLOGI) && 7755 + !(phba->fc_topology == 7756 + LPFC_TOPOLOGY_LOOP)) 7757 + bf_set(els_req64_sid, &wqe->els_req, 0); 7918 7758 bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); 7919 7759 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, 7920 - phba->vpi_ids[phba->pport->vpi]); 7760 + phba->vpi_ids[iocbq->vport->vpi]); 7921 7761 } else if (pcmd && iocbq->context1) { 7922 7762 bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); 7923 7763 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, ··· 8076 7908 /* words0-2 BDE memcpy */ 8077 7909 /* word3 iocb=iotag32 wqe=response_payload_len */ 8078 7910 wqe->xmit_els_rsp.response_payload_len = xmit_len; 8079 - /* word4 iocb=did wge=rsvd. */ 8080 - wqe->xmit_els_rsp.rsvd4 = 0; 7911 + /* word4 */ 7912 + wqe->xmit_els_rsp.word4 = 0; 8081 7913 /* word5 iocb=rsvd wge=did */ 8082 7914 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, 8083 - iocbq->iocb.un.elsreq64.remoteID); 7915 + iocbq->iocb.un.xseq64.xmit_els_remoteID); 7916 + 7917 + if_type = bf_get(lpfc_sli_intf_if_type, 7918 + &phba->sli4_hba.sli_intf); 7919 + if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { 7920 + if (iocbq->vport->fc_flag & FC_PT2PT) { 7921 + bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); 7922 + bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, 7923 + iocbq->vport->fc_myDID); 7924 + if (iocbq->vport->fc_myDID == Fabric_DID) { 7925 + bf_set(wqe_els_did, 7926 + &wqe->xmit_els_rsp.wqe_dest, 0); 7927 + } 7928 + } 7929 + } 8084 7930 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 8085 7931 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); 8086 7932 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); ··· 8114 7932 pcmd = (uint32_t *) (((struct lpfc_dmabuf *) 8115 7933 iocbq->context2)->virt); 8116 7934 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { 8117 - bf_set(els_req64_sp, &wqe->els_req, 1); 8118 - bf_set(els_req64_sid, &wqe->els_req, 7935 + bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); 7936 + bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, 8119 7937 iocbq->vport->fc_myDID); 8120 - bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); 8121 - bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, 7938 + bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); 7939 + bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 8122 7940 phba->vpi_ids[phba->pport->vpi]); 8123 7941 } 8124 7942 command_type = OTHER_COMMAND; ··· 13262 13080 } else { 13263 13081 set_bit(xri, phba->sli4_hba.xri_bmask); 13264 13082 phba->sli4_hba.max_cfg_param.xri_used++; 13265 - phba->sli4_hba.xri_count++; 13266 13083 } 13267 - 13268 13084 spin_unlock_irq(&phba->hbalock); 13269 13085 return xri; 13270 13086 } ··· 13278 13098 __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) 13279 13099 { 13280 13100 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { 13281 - phba->sli4_hba.xri_count--; 13282 13101 phba->sli4_hba.max_cfg_param.xri_used--; 13283 13102 } 13284 13103 } ··· 13313 13134 uint16_t xri_index; 13314 13135 13315 13136 xri_index = lpfc_sli4_alloc_xri(phba); 13316 - if (xri_index != NO_XRI) 13317 - return xri_index; 13318 - 13319 - lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 13320 - "2004 Failed to allocate XRI.last XRITAG is %d" 13321 - " Max XRI is %d, Used XRI is %d\n", 13322 - xri_index, 13323 - phba->sli4_hba.max_cfg_param.max_xri, 13324 - phba->sli4_hba.max_cfg_param.xri_used); 13325 - return NO_XRI; 13137 + if (xri_index == NO_XRI) 13138 + lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, 13139 + "2004 Failed to allocate XRI.last XRITAG is %d" 13140 + " Max XRI is %d, Used XRI is %d\n", 13141 + xri_index, 13142 + phba->sli4_hba.max_cfg_param.max_xri, 13143 + phba->sli4_hba.max_cfg_param.xri_used); 13144 + return xri_index; 13326 13145 } 13327 13146 13328 13147 /** 13329 13148 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port. 13330 13149 * @phba: pointer to lpfc hba data structure. 13150 + * @post_sgl_list: pointer to els sgl entry list. 13151 + * @count: number of els sgl entries on the list. 13331 13152 * 13332 13153 * This routine is invoked to post a block of driver's sgl pages to the 13333 13154 * HBA using non-embedded mailbox command. No Lock is held. This routine 13334 13155 * is only called when the driver is loading and after all IO has been 13335 13156 * stopped. 13336 13157 **/ 13337 - int 13338 - lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba) 13158 + static int 13159 + lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, 13160 + struct list_head *post_sgl_list, 13161 + int post_cnt) 13339 13162 { 13340 - struct lpfc_sglq *sglq_entry; 13163 + struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; 13341 13164 struct lpfc_mbx_post_uembed_sgl_page1 *sgl; 13342 13165 struct sgl_page_pairs *sgl_pg_pairs; 13343 13166 void *viraddr; 13344 13167 LPFC_MBOXQ_t *mbox; 13345 13168 uint32_t reqlen, alloclen, pg_pairs; 13346 13169 uint32_t mbox_tmo; 13347 - uint16_t xritag_start = 0, lxri = 0; 13348 - int els_xri_cnt, rc = 0; 13170 + uint16_t xritag_start = 0; 13171 + int rc = 0; 13349 13172 uint32_t shdr_status, shdr_add_status; 13350 13173 union lpfc_sli4_cfg_shdr *shdr; 13351 13174 13352 - /* The number of sgls to be posted */ 13353 - els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); 13354 - 13355 - reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + 13175 + reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + 13356 13176 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); 13357 13177 if (reqlen > SLI4_PAGE_SIZE) { 13358 13178 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, ··· 13381 13203 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; 13382 13204 sgl_pg_pairs = &sgl->sgl_pg_pairs; 13383 13205 13384 - for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) { 13385 - sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs]; 13386 - 13387 - /* 13388 - * Assign the sglq a physical xri only if the driver has not 13389 - * initialized those resources. A port reset only needs 13390 - * the sglq's posted. 13391 - */ 13392 - if (bf_get(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags) != 13393 - LPFC_XRI_RSRC_RDY) { 13394 - lxri = lpfc_sli4_next_xritag(phba); 13395 - if (lxri == NO_XRI) { 13396 - lpfc_sli4_mbox_cmd_free(phba, mbox); 13397 - return -ENOMEM; 13398 - } 13399 - sglq_entry->sli4_lxritag = lxri; 13400 - sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; 13401 - } 13402 - 13206 + pg_pairs = 0; 13207 + list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) { 13403 13208 /* Set up the sge entry */ 13404 13209 sgl_pg_pairs->sgl_pg0_addr_lo = 13405 13210 cpu_to_le32(putPaddrLow(sglq_entry->phys)); ··· 13397 13236 if (pg_pairs == 0) 13398 13237 xritag_start = sglq_entry->sli4_xritag; 13399 13238 sgl_pg_pairs++; 13239 + pg_pairs++; 13400 13240 } 13401 13241 13402 13242 /* Complete initialization and perform endian conversion. */ 13403 13243 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); 13404 - bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt); 13244 + bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt); 13405 13245 sgl->word0 = cpu_to_le32(sgl->word0); 13406 13246 if (!phba->sli4_hba.intr_enable) 13407 13247 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); ··· 13422 13260 shdr_status, shdr_add_status, rc); 13423 13261 rc = -ENXIO; 13424 13262 } 13425 - 13426 - if (rc == 0) 13427 - bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 13428 - LPFC_XRI_RSRC_RDY); 13429 - return rc; 13430 - } 13431 - 13432 - /** 13433 - * lpfc_sli4_post_els_sgl_list_ext - post a block of ELS sgls to the port. 13434 - * @phba: pointer to lpfc hba data structure. 13435 - * 13436 - * This routine is invoked to post a block of driver's sgl pages to the 13437 - * HBA using non-embedded mailbox command. No Lock is held. This routine 13438 - * is only called when the driver is loading and after all IO has been 13439 - * stopped. 13440 - **/ 13441 - int 13442 - lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba) 13443 - { 13444 - struct lpfc_sglq *sglq_entry; 13445 - struct lpfc_mbx_post_uembed_sgl_page1 *sgl; 13446 - struct sgl_page_pairs *sgl_pg_pairs; 13447 - void *viraddr; 13448 - LPFC_MBOXQ_t *mbox; 13449 - uint32_t reqlen, alloclen, index; 13450 - uint32_t mbox_tmo; 13451 - uint16_t rsrc_start, rsrc_size, els_xri_cnt, post_els_xri_cnt; 13452 - uint16_t xritag_start = 0, lxri = 0; 13453 - struct lpfc_rsrc_blks *rsrc_blk; 13454 - int cnt, ttl_cnt, rc = 0; 13455 - int loop_cnt; 13456 - uint32_t shdr_status, shdr_add_status; 13457 - union lpfc_sli4_cfg_shdr *shdr; 13458 - 13459 - /* The number of sgls to be posted */ 13460 - els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); 13461 - 13462 - reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + 13463 - sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); 13464 - if (reqlen > SLI4_PAGE_SIZE) { 13465 - lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, 13466 - "2989 Block sgl registration required DMA " 13467 - "size (%d) great than a page\n", reqlen); 13468 - return -ENOMEM; 13469 - } 13470 - 13471 - cnt = 0; 13472 - ttl_cnt = 0; 13473 - post_els_xri_cnt = els_xri_cnt; 13474 - list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list, 13475 - list) { 13476 - rsrc_start = rsrc_blk->rsrc_start; 13477 - rsrc_size = rsrc_blk->rsrc_size; 13478 - 13479 - lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 13480 - "3014 Working ELS Extent start %d, cnt %d\n", 13481 - rsrc_start, rsrc_size); 13482 - 13483 - loop_cnt = min(post_els_xri_cnt, rsrc_size); 13484 - if (loop_cnt < post_els_xri_cnt) { 13485 - post_els_xri_cnt -= loop_cnt; 13486 - ttl_cnt += loop_cnt; 13487 - } else 13488 - ttl_cnt += post_els_xri_cnt; 13489 - 13490 - mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 13491 - if (!mbox) 13492 - return -ENOMEM; 13493 - /* 13494 - * Allocate DMA memory and set up the non-embedded mailbox 13495 - * command. 13496 - */ 13497 - alloclen = lpfc_sli4_config(phba, mbox, 13498 - LPFC_MBOX_SUBSYSTEM_FCOE, 13499 - LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, 13500 - reqlen, LPFC_SLI4_MBX_NEMBED); 13501 - if (alloclen < reqlen) { 13502 - lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 13503 - "2987 Allocated DMA memory size (%d) " 13504 - "is less than the requested DMA memory " 13505 - "size (%d)\n", alloclen, reqlen); 13506 - lpfc_sli4_mbox_cmd_free(phba, mbox); 13507 - return -ENOMEM; 13508 - } 13509 - 13510 - /* Set up the SGL pages in the non-embedded DMA pages */ 13511 - viraddr = mbox->sge_array->addr[0]; 13512 - sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; 13513 - sgl_pg_pairs = &sgl->sgl_pg_pairs; 13514 - 13515 - /* 13516 - * The starting resource may not begin at zero. Control 13517 - * the loop variants via the block resource parameters, 13518 - * but handle the sge pointers with a zero-based index 13519 - * that doesn't get reset per loop pass. 13520 - */ 13521 - for (index = rsrc_start; 13522 - index < rsrc_start + loop_cnt; 13523 - index++) { 13524 - sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[cnt]; 13525 - 13526 - /* 13527 - * Assign the sglq a physical xri only if the driver 13528 - * has not initialized those resources. A port reset 13529 - * only needs the sglq's posted. 13530 - */ 13531 - if (bf_get(lpfc_xri_rsrc_rdy, 13532 - &phba->sli4_hba.sli4_flags) != 13533 - LPFC_XRI_RSRC_RDY) { 13534 - lxri = lpfc_sli4_next_xritag(phba); 13535 - if (lxri == NO_XRI) { 13536 - lpfc_sli4_mbox_cmd_free(phba, mbox); 13537 - rc = -ENOMEM; 13538 - goto err_exit; 13539 - } 13540 - sglq_entry->sli4_lxritag = lxri; 13541 - sglq_entry->sli4_xritag = 13542 - phba->sli4_hba.xri_ids[lxri]; 13543 - } 13544 - 13545 - /* Set up the sge entry */ 13546 - sgl_pg_pairs->sgl_pg0_addr_lo = 13547 - cpu_to_le32(putPaddrLow(sglq_entry->phys)); 13548 - sgl_pg_pairs->sgl_pg0_addr_hi = 13549 - cpu_to_le32(putPaddrHigh(sglq_entry->phys)); 13550 - sgl_pg_pairs->sgl_pg1_addr_lo = 13551 - cpu_to_le32(putPaddrLow(0)); 13552 - sgl_pg_pairs->sgl_pg1_addr_hi = 13553 - cpu_to_le32(putPaddrHigh(0)); 13554 - 13555 - /* Track the starting physical XRI for the mailbox. */ 13556 - if (index == rsrc_start) 13557 - xritag_start = sglq_entry->sli4_xritag; 13558 - sgl_pg_pairs++; 13559 - cnt++; 13560 - } 13561 - 13562 - /* Complete initialization and perform endian conversion. */ 13563 - rsrc_blk->rsrc_used += loop_cnt; 13564 - bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); 13565 - bf_set(lpfc_post_sgl_pages_xricnt, sgl, loop_cnt); 13566 - sgl->word0 = cpu_to_le32(sgl->word0); 13567 - 13568 - lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 13569 - "3015 Post ELS Extent SGL, start %d, " 13570 - "cnt %d, used %d\n", 13571 - xritag_start, loop_cnt, rsrc_blk->rsrc_used); 13572 - if (!phba->sli4_hba.intr_enable) 13573 - rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); 13574 - else { 13575 - mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); 13576 - rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); 13577 - } 13578 - shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; 13579 - shdr_status = bf_get(lpfc_mbox_hdr_status, 13580 - &shdr->response); 13581 - shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, 13582 - &shdr->response); 13583 - if (rc != MBX_TIMEOUT) 13584 - lpfc_sli4_mbox_cmd_free(phba, mbox); 13585 - if (shdr_status || shdr_add_status || rc) { 13586 - lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 13587 - "2988 POST_SGL_BLOCK mailbox " 13588 - "command failed status x%x " 13589 - "add_status x%x mbx status x%x\n", 13590 - shdr_status, shdr_add_status, rc); 13591 - rc = -ENXIO; 13592 - goto err_exit; 13593 - } 13594 - if (ttl_cnt >= els_xri_cnt) 13595 - break; 13596 - } 13597 - 13598 - err_exit: 13599 - if (rc == 0) 13600 - bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 13601 - LPFC_XRI_RSRC_RDY); 13602 13263 return rc; 13603 13264 } 13604 13265 ··· 13437 13452 * 13438 13453 **/ 13439 13454 int 13440 - lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist, 13441 - int cnt) 13455 + lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, 13456 + struct list_head *sblist, 13457 + int count) 13442 13458 { 13443 13459 struct lpfc_scsi_buf *psb; 13444 13460 struct lpfc_mbx_post_uembed_sgl_page1 *sgl; ··· 13455 13469 union lpfc_sli4_cfg_shdr *shdr; 13456 13470 13457 13471 /* Calculate the requested length of the dma memory */ 13458 - reqlen = cnt * sizeof(struct sgl_page_pairs) + 13472 + reqlen = count * sizeof(struct sgl_page_pairs) + 13459 13473 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); 13460 13474 if (reqlen > SLI4_PAGE_SIZE) { 13461 13475 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, ··· 13534 13548 "status x%x add_status x%x mbx status x%x\n", 13535 13549 shdr_status, shdr_add_status, rc); 13536 13550 rc = -ENXIO; 13537 - } 13538 - return rc; 13539 - } 13540 - 13541 - /** 13542 - * lpfc_sli4_post_scsi_sgl_blk_ext - post a block of scsi sgls to the port. 13543 - * @phba: pointer to lpfc hba data structure. 13544 - * @sblist: pointer to scsi buffer list. 13545 - * @count: number of scsi buffers on the list. 13546 - * 13547 - * This routine is invoked to post a block of @count scsi sgl pages from a 13548 - * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. 13549 - * No Lock is held. 13550 - * 13551 - **/ 13552 - int 13553 - lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba *phba, struct list_head *sblist, 13554 - int cnt) 13555 - { 13556 - struct lpfc_scsi_buf *psb = NULL; 13557 - struct lpfc_mbx_post_uembed_sgl_page1 *sgl; 13558 - struct sgl_page_pairs *sgl_pg_pairs; 13559 - void *viraddr; 13560 - LPFC_MBOXQ_t *mbox; 13561 - uint32_t reqlen, alloclen, pg_pairs; 13562 - uint32_t mbox_tmo; 13563 - uint16_t xri_start = 0, scsi_xri_start; 13564 - uint16_t rsrc_range; 13565 - int rc = 0, avail_cnt; 13566 - uint32_t shdr_status, shdr_add_status; 13567 - dma_addr_t pdma_phys_bpl1; 13568 - union lpfc_sli4_cfg_shdr *shdr; 13569 - struct lpfc_rsrc_blks *rsrc_blk; 13570 - uint32_t xri_cnt = 0; 13571 - 13572 - /* Calculate the total requested length of the dma memory */ 13573 - reqlen = cnt * sizeof(struct sgl_page_pairs) + 13574 - sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); 13575 - if (reqlen > SLI4_PAGE_SIZE) { 13576 - lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, 13577 - "2932 Block sgl registration required DMA " 13578 - "size (%d) great than a page\n", reqlen); 13579 - return -ENOMEM; 13580 - } 13581 - 13582 - /* 13583 - * The use of extents requires the driver to post the sgl headers 13584 - * in multiple postings to meet the contiguous resource assignment. 13585 - */ 13586 - psb = list_prepare_entry(psb, sblist, list); 13587 - scsi_xri_start = phba->sli4_hba.scsi_xri_start; 13588 - list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list, 13589 - list) { 13590 - rsrc_range = rsrc_blk->rsrc_start + rsrc_blk->rsrc_size; 13591 - if (rsrc_range < scsi_xri_start) 13592 - continue; 13593 - else if (rsrc_blk->rsrc_used >= rsrc_blk->rsrc_size) 13594 - continue; 13595 - else 13596 - avail_cnt = rsrc_blk->rsrc_size - rsrc_blk->rsrc_used; 13597 - 13598 - reqlen = (avail_cnt * sizeof(struct sgl_page_pairs)) + 13599 - sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); 13600 - /* 13601 - * Allocate DMA memory and set up the non-embedded mailbox 13602 - * command. The mbox is used to post an SGL page per loop 13603 - * but the DMA memory has a use-once semantic so the mailbox 13604 - * is used and freed per loop pass. 13605 - */ 13606 - mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 13607 - if (!mbox) { 13608 - lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 13609 - "2933 Failed to allocate mbox cmd " 13610 - "memory\n"); 13611 - return -ENOMEM; 13612 - } 13613 - alloclen = lpfc_sli4_config(phba, mbox, 13614 - LPFC_MBOX_SUBSYSTEM_FCOE, 13615 - LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, 13616 - reqlen, 13617 - LPFC_SLI4_MBX_NEMBED); 13618 - if (alloclen < reqlen) { 13619 - lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 13620 - "2934 Allocated DMA memory size (%d) " 13621 - "is less than the requested DMA memory " 13622 - "size (%d)\n", alloclen, reqlen); 13623 - lpfc_sli4_mbox_cmd_free(phba, mbox); 13624 - return -ENOMEM; 13625 - } 13626 - 13627 - /* Get the first SGE entry from the non-embedded DMA memory */ 13628 - viraddr = mbox->sge_array->addr[0]; 13629 - 13630 - /* Set up the SGL pages in the non-embedded DMA pages */ 13631 - sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; 13632 - sgl_pg_pairs = &sgl->sgl_pg_pairs; 13633 - 13634 - /* pg_pairs tracks posted SGEs per loop iteration. */ 13635 - pg_pairs = 0; 13636 - list_for_each_entry_continue(psb, sblist, list) { 13637 - /* Set up the sge entry */ 13638 - sgl_pg_pairs->sgl_pg0_addr_lo = 13639 - cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); 13640 - sgl_pg_pairs->sgl_pg0_addr_hi = 13641 - cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); 13642 - if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) 13643 - pdma_phys_bpl1 = psb->dma_phys_bpl + 13644 - SGL_PAGE_SIZE; 13645 - else 13646 - pdma_phys_bpl1 = 0; 13647 - sgl_pg_pairs->sgl_pg1_addr_lo = 13648 - cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); 13649 - sgl_pg_pairs->sgl_pg1_addr_hi = 13650 - cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); 13651 - /* Keep the first xri for this extent. */ 13652 - if (pg_pairs == 0) 13653 - xri_start = psb->cur_iocbq.sli4_xritag; 13654 - sgl_pg_pairs++; 13655 - pg_pairs++; 13656 - xri_cnt++; 13657 - 13658 - /* 13659 - * Track two exit conditions - the loop has constructed 13660 - * all of the caller's SGE pairs or all available 13661 - * resource IDs in this extent are consumed. 13662 - */ 13663 - if ((xri_cnt == cnt) || (pg_pairs >= avail_cnt)) 13664 - break; 13665 - } 13666 - rsrc_blk->rsrc_used += pg_pairs; 13667 - bf_set(lpfc_post_sgl_pages_xri, sgl, xri_start); 13668 - bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); 13669 - 13670 - lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 13671 - "3016 Post SCSI Extent SGL, start %d, cnt %d " 13672 - "blk use %d\n", 13673 - xri_start, pg_pairs, rsrc_blk->rsrc_used); 13674 - /* Perform endian conversion if necessary */ 13675 - sgl->word0 = cpu_to_le32(sgl->word0); 13676 - if (!phba->sli4_hba.intr_enable) 13677 - rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); 13678 - else { 13679 - mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); 13680 - rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); 13681 - } 13682 - shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; 13683 - shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); 13684 - shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, 13685 - &shdr->response); 13686 - if (rc != MBX_TIMEOUT) 13687 - lpfc_sli4_mbox_cmd_free(phba, mbox); 13688 - if (shdr_status || shdr_add_status || rc) { 13689 - lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 13690 - "2935 POST_SGL_BLOCK mailbox command " 13691 - "failed status x%x add_status x%x " 13692 - "mbx status x%x\n", 13693 - shdr_status, shdr_add_status, rc); 13694 - return -ENXIO; 13695 - } 13696 - 13697 - /* Post only what is requested. */ 13698 - if (xri_cnt >= cnt) 13699 - break; 13700 13551 } 13701 13552 return rc; 13702 13553 } ··· 13662 13839 uint32_t did = (fc_hdr->fh_d_id[0] << 16 | 13663 13840 fc_hdr->fh_d_id[1] << 8 | 13664 13841 fc_hdr->fh_d_id[2]); 13842 + 13665 13843 if (did == Fabric_DID) 13666 13844 return phba->pport; 13845 + if ((phba->pport->fc_flag & FC_PT2PT) && 13846 + !(phba->link_state == LPFC_HBA_READY)) 13847 + return phba->pport; 13848 + 13667 13849 vports = lpfc_create_vport_work_array(phba); 13668 13850 if (vports != NULL) 13669 13851 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { ··· 13961 14133 return NO_XRI; 13962 14134 } 13963 14135 13964 - 13965 14136 /** 13966 14137 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort 13967 14138 * @phba: Pointer to HBA context object. ··· 13975 14148 { 13976 14149 struct lpfc_iocbq *ctiocb = NULL; 13977 14150 struct lpfc_nodelist *ndlp; 13978 - uint16_t oxid, rxid; 14151 + uint16_t oxid, rxid, xri, lxri; 13979 14152 uint32_t sid, fctl; 13980 14153 IOCB_t *icmd; 13981 14154 int rc; ··· 13994 14167 "SID:x%x\n", oxid, sid); 13995 14168 return; 13996 14169 } 13997 - if (lpfc_sli4_xri_inrange(phba, rxid)) 13998 - lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0); 13999 14170 14000 14171 /* Allocate buffer for rsp iocb */ 14001 14172 ctiocb = lpfc_sli_get_iocbq(phba); ··· 14024 14199 ctiocb->sli4_lxritag = NO_XRI; 14025 14200 ctiocb->sli4_xritag = NO_XRI; 14026 14201 14202 + if (fctl & FC_FC_EX_CTX) 14203 + /* Exchange responder sent the abort so we 14204 + * own the oxid. 14205 + */ 14206 + xri = oxid; 14207 + else 14208 + xri = rxid; 14209 + lxri = lpfc_sli4_xri_inrange(phba, xri); 14210 + if (lxri != NO_XRI) 14211 + lpfc_set_rrq_active(phba, ndlp, lxri, 14212 + (xri == oxid) ? rxid : oxid, 0); 14027 14213 /* If the oxid maps to the FCP XRI range or if it is out of range, 14028 14214 * send a BLS_RJT. The driver no longer has that exchange. 14029 14215 * Override the IOCB for a BA_RJT. 14030 14216 */ 14031 - if (oxid > (phba->sli4_hba.max_cfg_param.max_xri + 14217 + if (xri > (phba->sli4_hba.max_cfg_param.max_xri + 14032 14218 phba->sli4_hba.max_cfg_param.xri_base) || 14033 - oxid > (lpfc_sli4_get_els_iocb_cnt(phba) + 14219 + xri > (lpfc_sli4_get_els_iocb_cnt(phba) + 14034 14220 phba->sli4_hba.max_cfg_param.xri_base)) { 14035 14221 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; 14036 14222 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); ··· 14213 14377 /* Initialize the first IOCB. */ 14214 14378 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; 14215 14379 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; 14216 - first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; 14380 + 14381 + /* Check FC Header to see what TYPE of frame we are rcv'ing */ 14382 + if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { 14383 + first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; 14384 + first_iocbq->iocb.un.rcvels.parmRo = 14385 + sli4_did_from_fc_hdr(fc_hdr); 14386 + first_iocbq->iocb.ulpPU = PARM_NPIV_DID; 14387 + } else 14388 + first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; 14217 14389 first_iocbq->iocb.ulpContext = NO_XRI; 14218 14390 first_iocbq->iocb.unsli3.rcvsli3.ox_id = 14219 14391 be16_to_cpu(fc_hdr->fh_ox_id); ··· 14351 14507 struct fc_frame_header *fc_hdr; 14352 14508 struct lpfc_vport *vport; 14353 14509 uint32_t fcfi; 14510 + uint32_t did; 14354 14511 14355 14512 /* Process each received buffer */ 14356 14513 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; ··· 14367 14522 else 14368 14523 fcfi = bf_get(lpfc_rcqe_fcf_id, 14369 14524 &dmabuf->cq_event.cqe.rcqe_cmpl); 14525 + 14370 14526 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); 14371 - if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) { 14527 + if (!vport) { 14372 14528 /* throw out the frame */ 14373 14529 lpfc_in_buf_free(phba, &dmabuf->dbuf); 14374 14530 return; 14375 14531 } 14532 + 14533 + /* d_id this frame is directed to */ 14534 + did = sli4_did_from_fc_hdr(fc_hdr); 14535 + 14536 + /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ 14537 + if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && 14538 + (did != Fabric_DID)) { 14539 + /* 14540 + * Throw out the frame if we are not pt2pt. 14541 + * The pt2pt protocol allows for discovery frames 14542 + * to be received without a registered VPI. 14543 + */ 14544 + if (!(vport->fc_flag & FC_PT2PT) || 14545 + (phba->link_state == LPFC_HBA_READY)) { 14546 + lpfc_in_buf_free(phba, &dmabuf->dbuf); 14547 + return; 14548 + } 14549 + } 14550 + 14376 14551 /* Handle the basic abort sequence (BA_ABTS) event */ 14377 14552 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { 14378 14553 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
+1 -1
drivers/scsi/lpfc/lpfc_sli.h
··· 68 68 #define LPFC_EXCHANGE_BUSY 0x40 /* SLI4 hba reported XB in response */ 69 69 #define LPFC_USE_FCPWQIDX 0x80 /* Submit to specified FCPWQ index */ 70 70 #define DSS_SECURITY_OP 0x100 /* security IO */ 71 - #define LPFC_IO_ON_Q 0x200 /* The IO is still on the TXCMPLQ */ 71 + #define LPFC_IO_ON_TXCMPLQ 0x200 /* The IO is still on the TXCMPLQ */ 72 72 #define LPFC_IO_DIF 0x400 /* T10 DIF IO */ 73 73 74 74 #define LPFC_FIP_ELS_ID_MASK 0xc000 /* ELS_ID range 0-3, non-shifted mask */
+9 -8
drivers/scsi/lpfc/lpfc_sli4.h
··· 75 75 (fc_hdr)->fh_s_id[1] << 8 | \ 76 76 (fc_hdr)->fh_s_id[2]) 77 77 78 + #define sli4_did_from_fc_hdr(fc_hdr) \ 79 + ((fc_hdr)->fh_d_id[0] << 16 | \ 80 + (fc_hdr)->fh_d_id[1] << 8 | \ 81 + (fc_hdr)->fh_d_id[2]) 82 + 78 83 #define sli4_fctl_from_fc_hdr(fc_hdr) \ 79 84 ((fc_hdr)->fh_f_ctl[0] << 16 | \ 80 85 (fc_hdr)->fh_f_ctl[1] << 8 | \ 81 86 (fc_hdr)->fh_f_ctl[2]) 87 + 88 + #define sli4_type_from_fc_hdr(fc_hdr) \ 89 + ((fc_hdr)->fh_type) 82 90 83 91 #define LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT 12000 84 92 ··· 501 493 uint16_t next_rpi; 502 494 uint16_t scsi_xri_max; 503 495 uint16_t scsi_xri_cnt; 496 + uint16_t els_xri_cnt; 504 497 uint16_t scsi_xri_start; 505 498 struct list_head lpfc_free_sgl_list; 506 499 struct list_head lpfc_sgl_list; 507 - struct lpfc_sglq **lpfc_els_sgl_array; 508 500 struct list_head lpfc_abts_els_sgl_list; 509 - struct lpfc_scsi_buf **lpfc_scsi_psb_array; 510 501 struct list_head lpfc_abts_scsi_buf_list; 511 - uint32_t total_sglq_bufs; 512 502 struct lpfc_sglq **lpfc_sglq_active_list; 513 503 struct list_head lpfc_rpi_hdr_list; 514 504 unsigned long *rpi_bmask; ··· 515 509 struct list_head lpfc_rpi_blk_list; 516 510 unsigned long *xri_bmask; 517 511 uint16_t *xri_ids; 518 - uint16_t xri_count; 519 512 struct list_head lpfc_xri_blk_list; 520 513 unsigned long *vfi_bmask; 521 514 uint16_t *vfi_ids; ··· 619 614 int lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *); 620 615 uint16_t lpfc_sli4_next_xritag(struct lpfc_hba *); 621 616 int lpfc_sli4_post_async_mbox(struct lpfc_hba *); 622 - int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba); 623 - int lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba); 624 617 int lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *, struct list_head *, int); 625 - int lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba *, struct list_head *, 626 - int); 627 618 struct lpfc_cq_event *__lpfc_sli4_cq_event_alloc(struct lpfc_hba *); 628 619 struct lpfc_cq_event *lpfc_sli4_cq_event_alloc(struct lpfc_hba *); 629 620 void __lpfc_sli4_cq_event_release(struct lpfc_hba *, struct lpfc_cq_event *);
+1 -1
drivers/scsi/lpfc/lpfc_version.h
··· 18 18 * included with this package. * 19 19 *******************************************************************/ 20 20 21 - #define LPFC_DRIVER_VERSION "8.3.30" 21 + #define LPFC_DRIVER_VERSION "8.3.31" 22 22 #define LPFC_DRIVER_NAME "lpfc" 23 23 #define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp" 24 24 #define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp"
+3 -3
drivers/scsi/megaraid/megaraid_sas.h
··· 33 33 /* 34 34 * MegaRAID SAS Driver meta data 35 35 */ 36 - #define MEGASAS_VERSION "00.00.06.14-rc1" 37 - #define MEGASAS_RELDATE "Jan. 6, 2012" 38 - #define MEGASAS_EXT_VERSION "Fri. Jan. 6 17:00:00 PDT 2012" 36 + #define MEGASAS_VERSION "00.00.06.15-rc1" 37 + #define MEGASAS_RELDATE "Mar. 19, 2012" 38 + #define MEGASAS_EXT_VERSION "Mon. Mar. 19 17:00:00 PDT 2012" 39 39 40 40 /* 41 41 * Device IDs
+1 -1
drivers/scsi/megaraid/megaraid_sas_base.c
··· 18 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 * 20 20 * FILE: megaraid_sas_base.c 21 - * Version : v00.00.06.14-rc1 21 + * Version : v00.00.06.15-rc1 22 22 * 23 23 * Authors: LSI Corporation 24 24 * Sreenivas Bagalkote
+13 -8
drivers/scsi/megaraid/megaraid_sas_fp.c
··· 362 362 /* assume this IO needs the full row - we'll adjust if not true */ 363 363 regSize = stripSize; 364 364 365 - /* If IO spans more than 1 strip, fp is not possible 366 - FP is not possible for writes on non-0 raid levels 367 - FP is not possible if LD is not capable */ 368 - if (num_strips > 1 || (!isRead && raid->level != 0) || 369 - !raid->capability.fpCapable) { 365 + /* Check if we can send this I/O via FastPath */ 366 + if (raid->capability.fpCapable) { 367 + if (isRead) 368 + io_info->fpOkForIo = (raid->capability.fpReadCapable && 369 + ((num_strips == 1) || 370 + raid->capability. 371 + fpReadAcrossStripe)); 372 + else 373 + io_info->fpOkForIo = (raid->capability.fpWriteCapable && 374 + ((num_strips == 1) || 375 + raid->capability. 376 + fpWriteAcrossStripe)); 377 + } else 370 378 io_info->fpOkForIo = FALSE; 371 - } else { 372 - io_info->fpOkForIo = TRUE; 373 - } 374 379 375 380 if (numRows == 1) { 376 381 /* single-strip IOs can always lock only the data needed */
+1 -3
drivers/scsi/megaraid/megaraid_sas_fusion.c
··· 634 634 fusion->reply_frames_desc_phys; 635 635 IOCInitMessage->SystemRequestFrameBaseAddress = 636 636 fusion->io_request_frames_phys; 637 - /* Set to 0 for none or 1 MSI-X vectors */ 638 - IOCInitMessage->HostMSIxVectors = (instance->msix_vectors > 0 ? 639 - instance->msix_vectors : 0); 637 + IOCInitMessage->HostMSIxVectors = instance->msix_vectors; 640 638 init_frame = (struct megasas_init_frame *)cmd->frame; 641 639 memset(init_frame, 0, MEGAMFI_FRAME_SIZE); 642 640
+4 -3
drivers/scsi/mpt2sas/mpi/mpi2.h
··· 8 8 * scatter/gather formats. 9 9 * Creation Date: June 21, 2006 10 10 * 11 - * mpi2.h Version: 02.00.22 11 + * mpi2.h Version: 02.00.23 12 12 * 13 13 * Version History 14 14 * --------------- ··· 71 71 * 03-09-11 02.00.20 Bumped MPI2_HEADER_VERSION_UNIT. 72 72 * 05-25-11 02.00.21 Bumped MPI2_HEADER_VERSION_UNIT. 73 73 * 08-24-11 02.00.22 Bumped MPI2_HEADER_VERSION_UNIT. 74 + * 11-18-11 02.00.23 Bumped MPI2_HEADER_VERSION_UNIT. 74 75 * -------------------------------------------------------------------------- 75 76 */ 76 77 ··· 97 96 #define MPI2_VERSION_02_00 (0x0200) 98 97 99 98 /* versioning for this MPI header set */ 100 - #define MPI2_HEADER_VERSION_UNIT (0x16) 99 + #define MPI2_HEADER_VERSION_UNIT (0x17) 101 100 #define MPI2_HEADER_VERSION_DEV (0x00) 102 101 #define MPI2_HEADER_VERSION_UNIT_MASK (0xFF00) 103 102 #define MPI2_HEADER_VERSION_UNIT_SHIFT (8) ··· 481 480 MPI2_RAID_ACCELERATOR_SUCCESS_REPLY_DESCRIPTOR RAIDAcceleratorSuccess; 482 481 U64 Words; 483 482 } MPI2_REPLY_DESCRIPTORS_UNION, MPI2_POINTER PTR_MPI2_REPLY_DESCRIPTORS_UNION, 484 - Mpi2ReplyDescriptorsUnion_t, MPI2_POINTER pMpi2ReplyDescriptorsUnion_t; 483 + Mpi2ReplyDescriptorsUnion_t, MPI2_POINTER pMpi2ReplyDescriptorsUnion_t; 485 484 486 485 487 486
+52 -16
drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
··· 6 6 * Title: MPI Configuration messages and pages 7 7 * Creation Date: November 10, 2006 8 8 * 9 - * mpi2_cnfg.h Version: 02.00.21 9 + * mpi2_cnfg.h Version: 02.00.22 10 10 * 11 11 * Version History 12 12 * --------------- ··· 146 146 * Added SpinupFlags field containing a Disable Spin-up 147 147 * bit to the MPI2_SAS_IOUNIT4_SPINUP_GROUP fields of 148 148 * SAS IO Unit Page 4. 149 - 149 + * 11-18-11 02.00.22 Added define MPI2_IOCPAGE6_CAP_FLAGS_4K_SECTORS_SUPPORT. 150 + * Added UEFIVersion field to BIOS Page 1 and defined new 151 + * BiosOptions bits. 150 152 * -------------------------------------------------------------------------- 151 153 */ 152 154 ··· 1133 1131 } MPI2_CONFIG_PAGE_IOC_6, MPI2_POINTER PTR_MPI2_CONFIG_PAGE_IOC_6, 1134 1132 Mpi2IOCPage6_t, MPI2_POINTER pMpi2IOCPage6_t; 1135 1133 1136 - #define MPI2_IOCPAGE6_PAGEVERSION (0x04) 1134 + #define MPI2_IOCPAGE6_PAGEVERSION (0x05) 1137 1135 1138 1136 /* defines for IOC Page 6 CapabilitiesFlags */ 1137 + #define MPI2_IOCPAGE6_CAP_FLAGS_4K_SECTORS_SUPPORT (0x00000020) 1139 1138 #define MPI2_IOCPAGE6_CAP_FLAGS_RAID10_SUPPORT (0x00000010) 1140 1139 #define MPI2_IOCPAGE6_CAP_FLAGS_RAID1_SUPPORT (0x00000008) 1141 1140 #define MPI2_IOCPAGE6_CAP_FLAGS_RAID1E_SUPPORT (0x00000004) ··· 1207 1204 1208 1205 typedef struct _MPI2_CONFIG_PAGE_BIOS_1 1209 1206 { 1210 - MPI2_CONFIG_PAGE_HEADER Header; /* 0x00 */ 1211 - U32 BiosOptions; /* 0x04 */ 1212 - U32 IOCSettings; /* 0x08 */ 1213 - U32 Reserved1; /* 0x0C */ 1214 - U32 DeviceSettings; /* 0x10 */ 1215 - U16 NumberOfDevices; /* 0x14 */ 1216 - U16 Reserved2; /* 0x16 */ 1217 - U16 IOTimeoutBlockDevicesNonRM; /* 0x18 */ 1218 - U16 IOTimeoutSequential; /* 0x1A */ 1219 - U16 IOTimeoutOther; /* 0x1C */ 1220 - U16 IOTimeoutBlockDevicesRM; /* 0x1E */ 1207 + MPI2_CONFIG_PAGE_HEADER Header; /* 0x00 */ 1208 + U32 BiosOptions; /* 0x04 */ 1209 + U32 IOCSettings; /* 0x08 */ 1210 + U32 Reserved1; /* 0x0C */ 1211 + U32 DeviceSettings; /* 0x10 */ 1212 + U16 NumberOfDevices; /* 0x14 */ 1213 + U16 UEFIVersion; /* 0x16 */ 1214 + U16 IOTimeoutBlockDevicesNonRM; /* 0x18 */ 1215 + U16 IOTimeoutSequential; /* 0x1A */ 1216 + U16 IOTimeoutOther; /* 0x1C */ 1217 + U16 IOTimeoutBlockDevicesRM; /* 0x1E */ 1221 1218 } MPI2_CONFIG_PAGE_BIOS_1, MPI2_POINTER PTR_MPI2_CONFIG_PAGE_BIOS_1, 1222 1219 Mpi2BiosPage1_t, MPI2_POINTER pMpi2BiosPage1_t; 1223 1220 1224 - #define MPI2_BIOSPAGE1_PAGEVERSION (0x04) 1221 + #define MPI2_BIOSPAGE1_PAGEVERSION (0x05) 1225 1222 1226 1223 /* values for BIOS Page 1 BiosOptions field */ 1227 - #define MPI2_BIOSPAGE1_OPTIONS_DISABLE_BIOS (0x00000001) 1224 + #define MPI2_BIOSPAGE1_OPTIONS_MASK_UEFI_HII_REGISTRATION (0x00000006) 1225 + #define MPI2_BIOSPAGE1_OPTIONS_ENABLE_UEFI_HII (0x00000000) 1226 + #define MPI2_BIOSPAGE1_OPTIONS_DISABLE_UEFI_HII (0x00000002) 1227 + #define MPI2_BIOSPAGE1_OPTIONS_VERSION_CHECK_UEFI_HII (0x00000004) 1228 + 1229 + #define MPI2_BIOSPAGE1_OPTIONS_DISABLE_BIOS (0x00000001) 1228 1230 1229 1231 /* values for BIOS Page 1 IOCSettings field */ 1230 1232 #define MPI2_BIOSPAGE1_IOCSET_MASK_BOOT_PREFERENCE (0x00030000) ··· 1255 1247 #define MPI2_BIOSPAGE1_DEVSET_DISABLE_RM_LUN (0x00000004) 1256 1248 #define MPI2_BIOSPAGE1_DEVSET_DISABLE_NON_RM_LUN (0x00000002) 1257 1249 #define MPI2_BIOSPAGE1_DEVSET_DISABLE_OTHER_LUN (0x00000001) 1250 + 1251 + /* defines for BIOS Page 1 UEFIVersion field */ 1252 + #define MPI2_BIOSPAGE1_UEFI_VER_MAJOR_MASK (0xFF00) 1253 + #define MPI2_BIOSPAGE1_UEFI_VER_MAJOR_SHIFT (8) 1254 + #define MPI2_BIOSPAGE1_UEFI_VER_MINOR_MASK (0x00FF) 1255 + #define MPI2_BIOSPAGE1_UEFI_VER_MINOR_SHIFT (0) 1256 + 1258 1257 1259 1258 1260 1259 /* BIOS Page 2 */ ··· 2230 2215 #define MPI2_SASIOUNIT8_PM_IOUNIT_SATA_PARTIAL_MODE (0x00000001) 2231 2216 2232 2217 2218 + 2219 + /* SAS IO Unit Page 16 */ 2220 + 2221 + typedef struct _MPI2_CONFIG_PAGE_SASIOUNIT16 { 2222 + MPI2_CONFIG_EXTENDED_PAGE_HEADER Header; /* 0x00 */ 2223 + U64 TimeStamp; /* 0x08 */ 2224 + U32 Reserved1; /* 0x10 */ 2225 + U32 Reserved2; /* 0x14 */ 2226 + U32 FastPathPendedRequests; /* 0x18 */ 2227 + U32 FastPathUnPendedRequests; /* 0x1C */ 2228 + U32 FastPathHostRequestStarts; /* 0x20 */ 2229 + U32 FastPathFirmwareRequestStarts; /* 0x24 */ 2230 + U32 FastPathHostCompletions; /* 0x28 */ 2231 + U32 FastPathFirmwareCompletions; /* 0x2C */ 2232 + U32 NonFastPathRequestStarts; /* 0x30 */ 2233 + U32 NonFastPathHostCompletions; /* 0x30 */ 2234 + } MPI2_CONFIG_PAGE_SASIOUNIT16, 2235 + MPI2_POINTER PTR_MPI2_CONFIG_PAGE_SASIOUNIT16, 2236 + Mpi2SasIOUnitPage16_t, MPI2_POINTER pMpi2SasIOUnitPage16_t; 2237 + 2238 + #define MPI2_SASIOUNITPAGE16_PAGEVERSION (0x00) 2233 2239 2234 2240 2235 2241 /****************************************************************************
+26 -12
drivers/scsi/mpt2sas/mpt2sas_base.c
··· 699 699 u16 ioc_status; 700 700 701 701 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); 702 + if (unlikely(!mpi_reply)) { 703 + printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", 704 + ioc->name, __FILE__, __LINE__, __func__); 705 + return; 706 + } 702 707 ioc_status = le16_to_cpu(mpi_reply->IOCStatus); 703 708 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING 704 709 if ((ioc_status & MPI2_IOCSTATUS_MASK) && ··· 935 930 else if (request_desript_type == 936 931 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS) 937 932 goto next; 938 - if (smid) 933 + if (smid) { 939 934 cb_idx = _base_get_cb_idx(ioc, smid); 940 - if (smid && cb_idx != 0xFF) { 941 - rc = mpt_callbacks[cb_idx](ioc, smid, msix_index, 942 - reply); 935 + if ((likely(cb_idx < MPT_MAX_CALLBACKS)) 936 + && (likely(mpt_callbacks[cb_idx] != NULL))) { 937 + rc = mpt_callbacks[cb_idx](ioc, smid, 938 + msix_index, reply); 943 939 if (reply) 944 - _base_display_reply_info(ioc, smid, msix_index, 945 - reply); 940 + _base_display_reply_info(ioc, smid, 941 + msix_index, reply); 946 942 if (rc) 947 943 mpt2sas_base_free_smid(ioc, smid); 944 + } 948 945 } 949 946 if (!smid) 950 947 _base_async_event(ioc, msix_index, reply); ··· 3350 3343 } 3351 3344 3352 3345 pfacts = &ioc->pfacts[port]; 3353 - memset(pfacts, 0, sizeof(Mpi2PortFactsReply_t)); 3346 + memset(pfacts, 0, sizeof(struct mpt2sas_port_facts)); 3354 3347 pfacts->PortNumber = mpi_reply.PortNumber; 3355 3348 pfacts->VP_ID = mpi_reply.VP_ID; 3356 3349 pfacts->VF_ID = mpi_reply.VF_ID; ··· 3392 3385 } 3393 3386 3394 3387 facts = &ioc->facts; 3395 - memset(facts, 0, sizeof(Mpi2IOCFactsReply_t)); 3388 + memset(facts, 0, sizeof(struct mpt2sas_facts)); 3396 3389 facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion); 3397 3390 facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion); 3398 3391 facts->VP_ID = mpi_reply.VP_ID; ··· 4160 4153 if (ioc->is_driver_loading) { 4161 4154 if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier 4162 4155 == 0x80) { 4163 - hide_flag = (u8) (ioc->manu_pg10.OEMSpecificFlags0 & 4156 + hide_flag = (u8) ( 4157 + le32_to_cpu(ioc->manu_pg10.OEMSpecificFlags0) & 4164 4158 MFG_PAGE10_HIDE_SSDS_MASK); 4165 4159 if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK) 4166 4160 ioc->mfg_pg10_hide_flag = hide_flag; ··· 4270 4262 goto out_free_resources; 4271 4263 4272 4264 ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts, 4273 - sizeof(Mpi2PortFactsReply_t), GFP_KERNEL); 4265 + sizeof(struct mpt2sas_port_facts), GFP_KERNEL); 4274 4266 if (!ioc->pfacts) { 4275 4267 r = -ENOMEM; 4276 4268 goto out_free_resources; ··· 4287 4279 goto out_free_resources; 4288 4280 4289 4281 init_waitqueue_head(&ioc->reset_wq); 4290 - 4291 4282 /* allocate memory pd handle bitmask list */ 4292 4283 ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8); 4293 4284 if (ioc->facts.MaxDevHandle % 8) ··· 4297 4290 r = -ENOMEM; 4298 4291 goto out_free_resources; 4299 4292 } 4300 - 4293 + ioc->blocking_handles = kzalloc(ioc->pd_handles_sz, 4294 + GFP_KERNEL); 4295 + if (!ioc->blocking_handles) { 4296 + r = -ENOMEM; 4297 + goto out_free_resources; 4298 + } 4301 4299 ioc->fwfault_debug = mpt2sas_fwfault_debug; 4302 4300 4303 4301 /* base internal command bits */ ··· 4389 4377 if (ioc->is_warpdrive) 4390 4378 kfree(ioc->reply_post_host_index); 4391 4379 kfree(ioc->pd_handles); 4380 + kfree(ioc->blocking_handles); 4392 4381 kfree(ioc->tm_cmds.reply); 4393 4382 kfree(ioc->transport_cmds.reply); 4394 4383 kfree(ioc->scsih_cmds.reply); ··· 4431 4418 if (ioc->is_warpdrive) 4432 4419 kfree(ioc->reply_post_host_index); 4433 4420 kfree(ioc->pd_handles); 4421 + kfree(ioc->blocking_handles); 4434 4422 kfree(ioc->pfacts); 4435 4423 kfree(ioc->ctl_cmds.reply); 4436 4424 kfree(ioc->ctl_cmds.sense);
+6 -4
drivers/scsi/mpt2sas/mpt2sas_base.h
··· 69 69 #define MPT2SAS_DRIVER_NAME "mpt2sas" 70 70 #define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>" 71 71 #define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver" 72 - #define MPT2SAS_DRIVER_VERSION "12.100.00.00" 73 - #define MPT2SAS_MAJOR_VERSION 12 72 + #define MPT2SAS_DRIVER_VERSION "13.100.00.00" 73 + #define MPT2SAS_MAJOR_VERSION 13 74 74 #define MPT2SAS_MINOR_VERSION 100 75 75 #define MPT2SAS_BUILD_VERSION 00 76 76 #define MPT2SAS_RELEASE_VERSION 00 ··· 720 720 * @io_missing_delay: time for IO completed by fw when PDR enabled 721 721 * @device_missing_delay: time for device missing by fw when PDR enabled 722 722 * @sas_id : used for setting volume target IDs 723 + * @blocking_handles: bitmask used to identify which devices need blocking 723 724 * @pd_handles : bitmask for PD handles 724 725 * @pd_handles_sz : size of pd_handle bitmask 725 726 * @config_page_sz: config page size ··· 890 889 u8 io_missing_delay; 891 890 u16 device_missing_delay; 892 891 int sas_id; 893 - 892 + void *blocking_handles; 894 893 void *pd_handles; 895 894 u16 pd_handles_sz; 896 895 ··· 1059 1058 void mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle); 1060 1059 void mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle); 1061 1060 void mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address); 1062 - void mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address); 1061 + void mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, 1062 + u64 sas_address); 1063 1063 struct _sas_node *mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, 1064 1064 u16 handle); 1065 1065 struct _sas_node *mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
+172 -216
drivers/scsi/mpt2sas/mpt2sas_ctl.c
··· 620 620 * @ioc: per adapter object 621 621 * @karg - (struct mpt2_ioctl_command) 622 622 * @mf - pointer to mf in user space 623 - * @state - NON_BLOCKING or BLOCKING 624 623 */ 625 624 static long 626 - _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc, 627 - struct mpt2_ioctl_command karg, void __user *mf, enum block_state state) 625 + _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command karg, 626 + void __user *mf) 628 627 { 629 628 MPI2RequestHeader_t *mpi_request = NULL, *request; 630 629 MPI2DefaultReply_t *mpi_reply; ··· 645 646 u16 wait_state_count; 646 647 647 648 issue_reset = 0; 648 - 649 - if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex)) 650 - return -EAGAIN; 651 - else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) 652 - return -ERESTARTSYS; 653 649 654 650 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { 655 651 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", ··· 865 871 if (smp_request->PassthroughFlags & 866 872 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE) 867 873 data = (u8 *)&smp_request->SGL; 868 - else 874 + else { 875 + if (unlikely(data_out == NULL)) { 876 + printk(KERN_ERR "failure at %s:%d/%s()!\n", 877 + __FILE__, __LINE__, __func__); 878 + mpt2sas_base_free_smid(ioc, smid); 879 + ret = -EINVAL; 880 + goto out; 881 + } 869 882 data = data_out; 883 + } 870 884 871 885 if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) { 872 886 ioc->ioc_link_reset_in_progress = 1; ··· 987 985 ret = -ENODATA; 988 986 if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || 989 987 mpi_request->Function == 990 - MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { 988 + MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || 989 + mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH)) { 991 990 printk(MPT2SAS_INFO_FMT "issue target reset: handle " 992 991 "= (0x%04x)\n", ioc->name, 993 992 le16_to_cpu(mpi_request->FunctionDependent1)); ··· 1016 1013 1017 1014 kfree(mpi_request); 1018 1015 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; 1019 - mutex_unlock(&ioc->ctl_cmds.mutex); 1020 1016 return ret; 1021 1017 } 1022 1018 1023 1019 /** 1024 1020 * _ctl_getiocinfo - main handler for MPT2IOCINFO opcode 1021 + * @ioc: per adapter object 1025 1022 * @arg - user space buffer containing ioctl content 1026 1023 */ 1027 1024 static long 1028 - _ctl_getiocinfo(void __user *arg) 1025 + _ctl_getiocinfo(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1029 1026 { 1030 1027 struct mpt2_ioctl_iocinfo karg; 1031 - struct MPT2SAS_ADAPTER *ioc; 1032 1028 1033 1029 if (copy_from_user(&karg, arg, sizeof(karg))) { 1034 1030 printk(KERN_ERR "failure at %s:%d/%s()!\n", 1035 1031 __FILE__, __LINE__, __func__); 1036 1032 return -EFAULT; 1037 1033 } 1038 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1039 - return -ENODEV; 1040 1034 1041 1035 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, 1042 1036 __func__)); ··· 1069 1069 1070 1070 /** 1071 1071 * _ctl_eventquery - main handler for MPT2EVENTQUERY opcode 1072 + * @ioc: per adapter object 1072 1073 * @arg - user space buffer containing ioctl content 1073 1074 */ 1074 1075 static long 1075 - _ctl_eventquery(void __user *arg) 1076 + _ctl_eventquery(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1076 1077 { 1077 1078 struct mpt2_ioctl_eventquery karg; 1078 - struct MPT2SAS_ADAPTER *ioc; 1079 1079 1080 1080 if (copy_from_user(&karg, arg, sizeof(karg))) { 1081 1081 printk(KERN_ERR "failure at %s:%d/%s()!\n", 1082 1082 __FILE__, __LINE__, __func__); 1083 1083 return -EFAULT; 1084 1084 } 1085 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1086 - return -ENODEV; 1087 1085 1088 1086 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, 1089 1087 __func__)); ··· 1100 1102 1101 1103 /** 1102 1104 * _ctl_eventenable - main handler for MPT2EVENTENABLE opcode 1105 + * @ioc: per adapter object 1103 1106 * @arg - user space buffer containing ioctl content 1104 1107 */ 1105 1108 static long 1106 - _ctl_eventenable(void __user *arg) 1109 + _ctl_eventenable(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1107 1110 { 1108 1111 struct mpt2_ioctl_eventenable karg; 1109 - struct MPT2SAS_ADAPTER *ioc; 1110 1112 1111 1113 if (copy_from_user(&karg, arg, sizeof(karg))) { 1112 1114 printk(KERN_ERR "failure at %s:%d/%s()!\n", 1113 1115 __FILE__, __LINE__, __func__); 1114 1116 return -EFAULT; 1115 1117 } 1116 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1117 - return -ENODEV; 1118 1118 1119 1119 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, 1120 1120 __func__)); ··· 1138 1142 1139 1143 /** 1140 1144 * _ctl_eventreport - main handler for MPT2EVENTREPORT opcode 1145 + * @ioc: per adapter object 1141 1146 * @arg - user space buffer containing ioctl content 1142 1147 */ 1143 1148 static long 1144 - _ctl_eventreport(void __user *arg) 1149 + _ctl_eventreport(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1145 1150 { 1146 1151 struct mpt2_ioctl_eventreport karg; 1147 - struct MPT2SAS_ADAPTER *ioc; 1148 1152 u32 number_bytes, max_events, max; 1149 1153 struct mpt2_ioctl_eventreport __user *uarg = arg; 1150 1154 ··· 1153 1157 __FILE__, __LINE__, __func__); 1154 1158 return -EFAULT; 1155 1159 } 1156 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1157 - return -ENODEV; 1158 1160 1159 1161 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, 1160 1162 __func__)); ··· 1182 1188 1183 1189 /** 1184 1190 * _ctl_do_reset - main handler for MPT2HARDRESET opcode 1191 + * @ioc: per adapter object 1185 1192 * @arg - user space buffer containing ioctl content 1186 1193 */ 1187 1194 static long 1188 - _ctl_do_reset(void __user *arg) 1195 + _ctl_do_reset(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1189 1196 { 1190 1197 struct mpt2_ioctl_diag_reset karg; 1191 - struct MPT2SAS_ADAPTER *ioc; 1192 1198 int retval; 1193 1199 1194 1200 if (copy_from_user(&karg, arg, sizeof(karg))) { ··· 1196 1202 __FILE__, __LINE__, __func__); 1197 1203 return -EFAULT; 1198 1204 } 1199 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1200 - return -ENODEV; 1201 1205 1202 1206 if (ioc->shost_recovery || ioc->pci_error_recovery || 1203 1207 ioc->is_driver_loading) ··· 1284 1292 1285 1293 /** 1286 1294 * _ctl_btdh_mapping - main handler for MPT2BTDHMAPPING opcode 1295 + * @ioc: per adapter object 1287 1296 * @arg - user space buffer containing ioctl content 1288 1297 */ 1289 1298 static long 1290 - _ctl_btdh_mapping(void __user *arg) 1299 + _ctl_btdh_mapping(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1291 1300 { 1292 1301 struct mpt2_ioctl_btdh_mapping karg; 1293 - struct MPT2SAS_ADAPTER *ioc; 1294 1302 int rc; 1295 1303 1296 1304 if (copy_from_user(&karg, arg, sizeof(karg))) { ··· 1298 1306 __FILE__, __LINE__, __func__); 1299 1307 return -EFAULT; 1300 1308 } 1301 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1302 - return -ENODEV; 1303 1309 1304 1310 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, 1305 1311 __func__)); ··· 1566 1576 1567 1577 /** 1568 1578 * _ctl_diag_register - application register with driver 1579 + * @ioc: per adapter object 1569 1580 * @arg - user space buffer containing ioctl content 1570 - * @state - NON_BLOCKING or BLOCKING 1571 1581 * 1572 1582 * This will allow the driver to setup any required buffers that will be 1573 1583 * needed by firmware to communicate with the driver. 1574 1584 */ 1575 1585 static long 1576 - _ctl_diag_register(void __user *arg, enum block_state state) 1586 + _ctl_diag_register(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1577 1587 { 1578 1588 struct mpt2_diag_register karg; 1579 - struct MPT2SAS_ADAPTER *ioc; 1580 1589 long rc; 1581 1590 1582 1591 if (copy_from_user(&karg, arg, sizeof(karg))) { ··· 1583 1594 __FILE__, __LINE__, __func__); 1584 1595 return -EFAULT; 1585 1596 } 1586 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1587 - return -ENODEV; 1588 1597 1589 - if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex)) 1590 - return -EAGAIN; 1591 - else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) 1592 - return -ERESTARTSYS; 1593 1598 rc = _ctl_diag_register_2(ioc, &karg); 1594 - mutex_unlock(&ioc->ctl_cmds.mutex); 1595 1599 return rc; 1596 1600 } 1597 1601 1598 1602 /** 1599 1603 * _ctl_diag_unregister - application unregister with driver 1604 + * @ioc: per adapter object 1600 1605 * @arg - user space buffer containing ioctl content 1601 1606 * 1602 1607 * This will allow the driver to cleanup any memory allocated for diag 1603 1608 * messages and to free up any resources. 1604 1609 */ 1605 1610 static long 1606 - _ctl_diag_unregister(void __user *arg) 1611 + _ctl_diag_unregister(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1607 1612 { 1608 1613 struct mpt2_diag_unregister karg; 1609 - struct MPT2SAS_ADAPTER *ioc; 1610 1614 void *request_data; 1611 1615 dma_addr_t request_data_dma; 1612 1616 u32 request_data_sz; ··· 1610 1628 __FILE__, __LINE__, __func__); 1611 1629 return -EFAULT; 1612 1630 } 1613 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1614 - return -ENODEV; 1615 1631 1616 1632 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, 1617 1633 __func__)); ··· 1658 1678 1659 1679 /** 1660 1680 * _ctl_diag_query - query relevant info associated with diag buffers 1681 + * @ioc: per adapter object 1661 1682 * @arg - user space buffer containing ioctl content 1662 1683 * 1663 1684 * The application will send only buffer_type and unique_id. Driver will ··· 1666 1685 * 0x00, the driver will return info specified by Buffer Type. 1667 1686 */ 1668 1687 static long 1669 - _ctl_diag_query(void __user *arg) 1688 + _ctl_diag_query(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1670 1689 { 1671 1690 struct mpt2_diag_query karg; 1672 - struct MPT2SAS_ADAPTER *ioc; 1673 1691 void *request_data; 1674 1692 int i; 1675 1693 u8 buffer_type; ··· 1678 1698 __FILE__, __LINE__, __func__); 1679 1699 return -EFAULT; 1680 1700 } 1681 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1682 - return -ENODEV; 1683 1701 1684 1702 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, 1685 1703 __func__)); ··· 1844 1866 /** 1845 1867 * _ctl_diag_release - request to send Diag Release Message to firmware 1846 1868 * @arg - user space buffer containing ioctl content 1847 - * @state - NON_BLOCKING or BLOCKING 1848 1869 * 1849 1870 * This allows ownership of the specified buffer to returned to the driver, 1850 1871 * allowing an application to read the buffer without fear that firmware is 1851 1872 * overwritting information in the buffer. 1852 1873 */ 1853 1874 static long 1854 - _ctl_diag_release(void __user *arg, enum block_state state) 1875 + _ctl_diag_release(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1855 1876 { 1856 1877 struct mpt2_diag_release karg; 1857 - struct MPT2SAS_ADAPTER *ioc; 1858 1878 void *request_data; 1859 1879 int rc; 1860 1880 u8 buffer_type; ··· 1863 1887 __FILE__, __LINE__, __func__); 1864 1888 return -EFAULT; 1865 1889 } 1866 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1867 - return -ENODEV; 1868 1890 1869 1891 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, 1870 1892 __func__)); ··· 1916 1942 return 0; 1917 1943 } 1918 1944 1919 - if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex)) 1920 - return -EAGAIN; 1921 - else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) 1922 - return -ERESTARTSYS; 1923 - 1924 1945 rc = _ctl_send_release(ioc, buffer_type, &issue_reset); 1925 1946 1926 1947 if (issue_reset) 1927 1948 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, 1928 1949 FORCE_BIG_HAMMER); 1929 1950 1930 - mutex_unlock(&ioc->ctl_cmds.mutex); 1931 1951 return rc; 1932 1952 } 1933 1953 1934 1954 /** 1935 1955 * _ctl_diag_read_buffer - request for copy of the diag buffer 1956 + * @ioc: per adapter object 1936 1957 * @arg - user space buffer containing ioctl content 1937 - * @state - NON_BLOCKING or BLOCKING 1938 1958 */ 1939 1959 static long 1940 - _ctl_diag_read_buffer(void __user *arg, enum block_state state) 1960 + _ctl_diag_read_buffer(struct MPT2SAS_ADAPTER *ioc, void __user *arg) 1941 1961 { 1942 1962 struct mpt2_diag_read_buffer karg; 1943 1963 struct mpt2_diag_read_buffer __user *uarg = arg; 1944 - struct MPT2SAS_ADAPTER *ioc; 1945 1964 void *request_data, *diag_data; 1946 1965 Mpi2DiagBufferPostRequest_t *mpi_request; 1947 1966 Mpi2DiagBufferPostReply_t *mpi_reply; ··· 1950 1983 __FILE__, __LINE__, __func__); 1951 1984 return -EFAULT; 1952 1985 } 1953 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1954 - return -ENODEV; 1955 1986 1956 1987 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, 1957 1988 __func__)); ··· 2020 2055 } 2021 2056 /* Get a free request frame and save the message context. 2022 2057 */ 2023 - if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex)) 2024 - return -EAGAIN; 2025 - else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) 2026 - return -ERESTARTSYS; 2027 2058 2028 2059 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { 2029 2060 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", ··· 2100 2139 out: 2101 2140 2102 2141 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; 2103 - mutex_unlock(&ioc->ctl_cmds.mutex); 2104 2142 return rc; 2105 2143 } 2106 2144 2107 - /** 2108 - * _ctl_ioctl_main - main ioctl entry point 2109 - * @file - (struct file) 2110 - * @cmd - ioctl opcode 2111 - * @arg - 2112 - */ 2113 - static long 2114 - _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg) 2115 - { 2116 - enum block_state state; 2117 - long ret = -EINVAL; 2118 - 2119 - state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : 2120 - BLOCKING; 2121 - 2122 - switch (cmd) { 2123 - case MPT2IOCINFO: 2124 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_iocinfo)) 2125 - ret = _ctl_getiocinfo(arg); 2126 - break; 2127 - case MPT2COMMAND: 2128 - { 2129 - struct mpt2_ioctl_command karg; 2130 - struct mpt2_ioctl_command __user *uarg; 2131 - struct MPT2SAS_ADAPTER *ioc; 2132 - 2133 - if (copy_from_user(&karg, arg, sizeof(karg))) { 2134 - printk(KERN_ERR "failure at %s:%d/%s()!\n", 2135 - __FILE__, __LINE__, __func__); 2136 - return -EFAULT; 2137 - } 2138 - 2139 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || 2140 - !ioc) 2141 - return -ENODEV; 2142 - 2143 - if (ioc->shost_recovery || ioc->pci_error_recovery || 2144 - ioc->is_driver_loading) 2145 - return -EAGAIN; 2146 - 2147 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_command)) { 2148 - uarg = arg; 2149 - ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf, state); 2150 - } 2151 - break; 2152 - } 2153 - case MPT2EVENTQUERY: 2154 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventquery)) 2155 - ret = _ctl_eventquery(arg); 2156 - break; 2157 - case MPT2EVENTENABLE: 2158 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventenable)) 2159 - ret = _ctl_eventenable(arg); 2160 - break; 2161 - case MPT2EVENTREPORT: 2162 - ret = _ctl_eventreport(arg); 2163 - break; 2164 - case MPT2HARDRESET: 2165 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_diag_reset)) 2166 - ret = _ctl_do_reset(arg); 2167 - break; 2168 - case MPT2BTDHMAPPING: 2169 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_btdh_mapping)) 2170 - ret = _ctl_btdh_mapping(arg); 2171 - break; 2172 - case MPT2DIAGREGISTER: 2173 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_register)) 2174 - ret = _ctl_diag_register(arg, state); 2175 - break; 2176 - case MPT2DIAGUNREGISTER: 2177 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_unregister)) 2178 - ret = _ctl_diag_unregister(arg); 2179 - break; 2180 - case MPT2DIAGQUERY: 2181 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_query)) 2182 - ret = _ctl_diag_query(arg); 2183 - break; 2184 - case MPT2DIAGRELEASE: 2185 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_release)) 2186 - ret = _ctl_diag_release(arg, state); 2187 - break; 2188 - case MPT2DIAGREADBUFFER: 2189 - if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_read_buffer)) 2190 - ret = _ctl_diag_read_buffer(arg, state); 2191 - break; 2192 - default: 2193 - { 2194 - struct mpt2_ioctl_command karg; 2195 - struct MPT2SAS_ADAPTER *ioc; 2196 - 2197 - if (copy_from_user(&karg, arg, sizeof(karg))) { 2198 - printk(KERN_ERR "failure at %s:%d/%s()!\n", 2199 - __FILE__, __LINE__, __func__); 2200 - return -EFAULT; 2201 - } 2202 - 2203 - if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || 2204 - !ioc) 2205 - return -ENODEV; 2206 - 2207 - dctlprintk(ioc, printk(MPT2SAS_INFO_FMT 2208 - "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd)); 2209 - break; 2210 - } 2211 - } 2212 - return ret; 2213 - } 2214 - 2215 - /** 2216 - * _ctl_ioctl - main ioctl entry point (unlocked) 2217 - * @file - (struct file) 2218 - * @cmd - ioctl opcode 2219 - * @arg - 2220 - */ 2221 - static long 2222 - _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 2223 - { 2224 - long ret; 2225 - 2226 - mutex_lock(&_ctl_mutex); 2227 - ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); 2228 - mutex_unlock(&_ctl_mutex); 2229 - return ret; 2230 - } 2231 2145 2232 2146 #ifdef CONFIG_COMPAT 2233 2147 /** 2234 2148 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit. 2235 - * @file - (struct file) 2149 + * @ioc: per adapter object 2236 2150 * @cmd - ioctl opcode 2237 2151 * @arg - (struct mpt2_ioctl_command32) 2238 2152 * 2239 2153 * MPT2COMMAND32 - Handle 32bit applications running on 64bit os. 2240 2154 */ 2241 2155 static long 2242 - _ctl_compat_mpt_command(struct file *file, unsigned cmd, unsigned long arg) 2156 + _ctl_compat_mpt_command(struct MPT2SAS_ADAPTER *ioc, unsigned cmd, 2157 + void __user *arg) 2243 2158 { 2244 2159 struct mpt2_ioctl_command32 karg32; 2245 2160 struct mpt2_ioctl_command32 __user *uarg; 2246 2161 struct mpt2_ioctl_command karg; 2247 - struct MPT2SAS_ADAPTER *ioc; 2248 - enum block_state state; 2249 2162 2250 2163 if (_IOC_SIZE(cmd) != sizeof(struct mpt2_ioctl_command32)) 2251 2164 return -EINVAL; ··· 2131 2296 __FILE__, __LINE__, __func__); 2132 2297 return -EFAULT; 2133 2298 } 2134 - if (_ctl_verify_adapter(karg32.hdr.ioc_number, &ioc) == -1 || !ioc) 2135 - return -ENODEV; 2136 - 2137 - if (ioc->shost_recovery || ioc->pci_error_recovery || 2138 - ioc->is_driver_loading) 2139 - return -EAGAIN; 2140 2299 2141 2300 memset(&karg, 0, sizeof(struct mpt2_ioctl_command)); 2142 2301 karg.hdr.ioc_number = karg32.hdr.ioc_number; ··· 2146 2317 karg.data_in_buf_ptr = compat_ptr(karg32.data_in_buf_ptr); 2147 2318 karg.data_out_buf_ptr = compat_ptr(karg32.data_out_buf_ptr); 2148 2319 karg.sense_data_ptr = compat_ptr(karg32.sense_data_ptr); 2320 + return _ctl_do_mpt_command(ioc, karg, &uarg->mf); 2321 + } 2322 + #endif 2323 + 2324 + /** 2325 + * _ctl_ioctl_main - main ioctl entry point 2326 + * @file - (struct file) 2327 + * @cmd - ioctl opcode 2328 + * @arg - 2329 + * compat - handles 32 bit applications in 64bit os 2330 + */ 2331 + static long 2332 + _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg, 2333 + u8 compat) 2334 + { 2335 + struct MPT2SAS_ADAPTER *ioc; 2336 + struct mpt2_ioctl_header ioctl_header; 2337 + enum block_state state; 2338 + long ret = -EINVAL; 2339 + 2340 + /* get IOCTL header */ 2341 + if (copy_from_user(&ioctl_header, (char __user *)arg, 2342 + sizeof(struct mpt2_ioctl_header))) { 2343 + printk(KERN_ERR "failure at %s:%d/%s()!\n", 2344 + __FILE__, __LINE__, __func__); 2345 + return -EFAULT; 2346 + } 2347 + 2348 + if (_ctl_verify_adapter(ioctl_header.ioc_number, &ioc) == -1 || !ioc) 2349 + return -ENODEV; 2350 + if (ioc->shost_recovery || ioc->pci_error_recovery || 2351 + ioc->is_driver_loading) 2352 + return -EAGAIN; 2353 + 2149 2354 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING; 2150 - return _ctl_do_mpt_command(ioc, karg, &uarg->mf, state); 2355 + if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex)) 2356 + return -EAGAIN; 2357 + else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) 2358 + return -ERESTARTSYS; 2359 + 2360 + switch (cmd) { 2361 + case MPT2IOCINFO: 2362 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_iocinfo)) 2363 + ret = _ctl_getiocinfo(ioc, arg); 2364 + break; 2365 + #ifdef CONFIG_COMPAT 2366 + case MPT2COMMAND32: 2367 + #endif 2368 + case MPT2COMMAND: 2369 + { 2370 + struct mpt2_ioctl_command __user *uarg; 2371 + struct mpt2_ioctl_command karg; 2372 + #ifdef CONFIG_COMPAT 2373 + if (compat) { 2374 + ret = _ctl_compat_mpt_command(ioc, cmd, arg); 2375 + break; 2376 + } 2377 + #endif 2378 + if (copy_from_user(&karg, arg, sizeof(karg))) { 2379 + printk(KERN_ERR "failure at %s:%d/%s()!\n", 2380 + __FILE__, __LINE__, __func__); 2381 + ret = -EFAULT; 2382 + break; 2383 + } 2384 + 2385 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_command)) { 2386 + uarg = arg; 2387 + ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf); 2388 + } 2389 + break; 2390 + } 2391 + case MPT2EVENTQUERY: 2392 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventquery)) 2393 + ret = _ctl_eventquery(ioc, arg); 2394 + break; 2395 + case MPT2EVENTENABLE: 2396 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventenable)) 2397 + ret = _ctl_eventenable(ioc, arg); 2398 + break; 2399 + case MPT2EVENTREPORT: 2400 + ret = _ctl_eventreport(ioc, arg); 2401 + break; 2402 + case MPT2HARDRESET: 2403 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_diag_reset)) 2404 + ret = _ctl_do_reset(ioc, arg); 2405 + break; 2406 + case MPT2BTDHMAPPING: 2407 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_btdh_mapping)) 2408 + ret = _ctl_btdh_mapping(ioc, arg); 2409 + break; 2410 + case MPT2DIAGREGISTER: 2411 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_register)) 2412 + ret = _ctl_diag_register(ioc, arg); 2413 + break; 2414 + case MPT2DIAGUNREGISTER: 2415 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_unregister)) 2416 + ret = _ctl_diag_unregister(ioc, arg); 2417 + break; 2418 + case MPT2DIAGQUERY: 2419 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_query)) 2420 + ret = _ctl_diag_query(ioc, arg); 2421 + break; 2422 + case MPT2DIAGRELEASE: 2423 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_release)) 2424 + ret = _ctl_diag_release(ioc, arg); 2425 + break; 2426 + case MPT2DIAGREADBUFFER: 2427 + if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_read_buffer)) 2428 + ret = _ctl_diag_read_buffer(ioc, arg); 2429 + break; 2430 + default: 2431 + 2432 + dctlprintk(ioc, printk(MPT2SAS_INFO_FMT 2433 + "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd)); 2434 + break; 2435 + } 2436 + 2437 + mutex_unlock(&ioc->ctl_cmds.mutex); 2438 + return ret; 2151 2439 } 2152 2440 2441 + /** 2442 + * _ctl_ioctl - main ioctl entry point (unlocked) 2443 + * @file - (struct file) 2444 + * @cmd - ioctl opcode 2445 + * @arg - 2446 + */ 2447 + static long 2448 + _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 2449 + { 2450 + long ret; 2451 + 2452 + ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0); 2453 + return ret; 2454 + } 2455 + #ifdef CONFIG_COMPAT 2153 2456 /** 2154 2457 * _ctl_ioctl_compat - main ioctl entry point (compat) 2155 2458 * @file - ··· 2295 2334 { 2296 2335 long ret; 2297 2336 2298 - mutex_lock(&_ctl_mutex); 2299 - if (cmd == MPT2COMMAND32) 2300 - ret = _ctl_compat_mpt_command(file, cmd, arg); 2301 - else 2302 - ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); 2303 - mutex_unlock(&_ctl_mutex); 2337 + ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1); 2304 2338 return ret; 2305 2339 } 2306 2340 #endif ··· 2840 2884 struct mpt2_diag_register diag_register; 2841 2885 u8 issue_reset = 0; 2842 2886 2843 - if (sscanf(buf, "%s", str) != 1) 2887 + if (sscanf(buf, "%9s", str) != 1) 2844 2888 return -EINVAL; 2845 2889 2846 2890 if (!strcmp(str, "post")) {
+329 -268
drivers/scsi/mpt2sas/mpt2sas_scsih.c
··· 579 579 return; 580 580 581 581 spin_lock_irqsave(&ioc->sas_device_lock, flags); 582 - if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 583 - sas_device->sas_address)) { 584 - list_del(&sas_device->list); 585 - kfree(sas_device); 586 - } 582 + list_del(&sas_device->list); 583 + kfree(sas_device); 587 584 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 588 585 } 586 + 589 587 590 588 /** 591 589 * _scsih_sas_device_add - insert sas_device to the list. ··· 643 645 644 646 spin_lock_irqsave(&ioc->sas_device_lock, flags); 645 647 list_add_tail(&sas_device->list, &ioc->sas_device_init_list); 646 - spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 647 648 _scsih_determine_boot_device(ioc, sas_device, 0); 649 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 648 650 } 649 651 650 652 /** ··· 753 755 * @ioc: per adapter object 754 756 * @raid_device: raid_device object 755 757 * 756 - * This is removed from the raid_device_list link list. 757 758 */ 758 759 static void 759 760 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc, ··· 762 765 763 766 spin_lock_irqsave(&ioc->raid_device_lock, flags); 764 767 list_del(&raid_device->list); 765 - memset(raid_device, 0, sizeof(struct _raid_device)); 766 768 kfree(raid_device); 767 769 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 768 770 } ··· 1195 1199 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1196 1200 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 1197 1201 sas_device_priv_data->sas_target->sas_address); 1198 - spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1199 1202 if (sas_device && sas_device->device_info & 1200 1203 MPI2_SAS_DEVICE_INFO_SATA_DEVICE) 1201 1204 max_depth = MPT2SAS_SATA_QUEUE_DEPTH; 1205 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1202 1206 1203 1207 not_sata: 1204 1208 ··· 1295 1299 sas_target_priv_data->handle = raid_device->handle; 1296 1300 sas_target_priv_data->sas_address = raid_device->wwid; 1297 1301 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; 1298 - sas_target_priv_data->raid_device = raid_device; 1302 + if (ioc->is_warpdrive) 1303 + sas_target_priv_data->raid_device = raid_device; 1299 1304 raid_device->starget = starget; 1300 1305 } 1301 1306 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); ··· 1462 1465 /** 1463 1466 * _scsih_display_sata_capabilities - sata capabilities 1464 1467 * @ioc: per adapter object 1465 - * @sas_device: the sas_device object 1468 + * @handle: device handle 1466 1469 * @sdev: scsi device struct 1467 1470 */ 1468 1471 static void 1469 1472 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, 1470 - struct _sas_device *sas_device, struct scsi_device *sdev) 1473 + u16 handle, struct scsi_device *sdev) 1471 1474 { 1472 1475 Mpi2ConfigReply_t mpi_reply; 1473 1476 Mpi2SasDevicePage0_t sas_device_pg0; ··· 1476 1479 u32 device_info; 1477 1480 1478 1481 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, 1479 - MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) { 1482 + MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { 1480 1483 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1481 1484 ioc->name, __FILE__, __LINE__, __func__); 1482 1485 return; ··· 1534 1537 Mpi2RaidVolPage0_t vol_pg0; 1535 1538 Mpi2ConfigReply_t mpi_reply; 1536 1539 u32 volume_status_flags; 1537 - u8 percent_complete = 0; 1540 + u8 percent_complete; 1541 + u16 handle; 1542 + 1543 + percent_complete = 0; 1544 + handle = 0; 1545 + if (ioc->is_warpdrive) 1546 + goto out; 1538 1547 1539 1548 spin_lock_irqsave(&ioc->raid_device_lock, flags); 1540 1549 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, 1541 1550 sdev->channel); 1551 + if (raid_device) { 1552 + handle = raid_device->handle; 1553 + percent_complete = raid_device->percent_complete; 1554 + } 1542 1555 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 1543 1556 1544 - if (!raid_device || ioc->is_warpdrive) 1557 + if (!handle) 1545 1558 goto out; 1546 1559 1547 1560 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, 1548 - MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, 1561 + MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, 1549 1562 sizeof(Mpi2RaidVolPage0_t))) { 1550 1563 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1551 1564 ioc->name, __FILE__, __LINE__, __func__); 1565 + percent_complete = 0; 1552 1566 goto out; 1553 1567 } 1554 1568 1555 1569 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); 1556 - if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) 1557 - percent_complete = raid_device->percent_complete; 1570 + if (!(volume_status_flags & 1571 + MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) 1572 + percent_complete = 0; 1573 + 1558 1574 out: 1559 1575 raid_set_resync(mpt2sas_raid_template, dev, percent_complete); 1560 1576 } ··· 1587 1577 Mpi2ConfigReply_t mpi_reply; 1588 1578 u32 volstate; 1589 1579 enum raid_state state = RAID_STATE_UNKNOWN; 1580 + u16 handle = 0; 1590 1581 1591 1582 spin_lock_irqsave(&ioc->raid_device_lock, flags); 1592 1583 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, 1593 1584 sdev->channel); 1585 + if (raid_device) 1586 + handle = raid_device->handle; 1594 1587 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 1595 1588 1596 1589 if (!raid_device) 1597 1590 goto out; 1598 1591 1599 1592 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, 1600 - MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, 1593 + MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, 1601 1594 sizeof(Mpi2RaidVolPage0_t))) { 1602 1595 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1603 1596 ioc->name, __FILE__, __LINE__, __func__); ··· 1633 1620 /** 1634 1621 * _scsih_set_level - set raid level 1635 1622 * @sdev: scsi device struct 1636 - * @raid_device: raid_device object 1623 + * @volume_type: volume type 1637 1624 */ 1638 1625 static void 1639 - _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device) 1626 + _scsih_set_level(struct scsi_device *sdev, u8 volume_type) 1640 1627 { 1641 1628 enum raid_level level = RAID_LEVEL_UNKNOWN; 1642 1629 1643 - switch (raid_device->volume_type) { 1630 + switch (volume_type) { 1644 1631 case MPI2_RAID_VOL_TYPE_RAID0: 1645 1632 level = RAID_LEVEL_0; 1646 1633 break; ··· 1735 1722 struct _raid_device *raid_device; 1736 1723 u16 handle; 1737 1724 u16 ioc_status; 1725 + unsigned long flags; 1738 1726 1739 1727 handle = 0xFFFF; 1740 1728 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, ··· 1745 1731 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) 1746 1732 break; 1747 1733 handle = le16_to_cpu(vol_pg1.DevHandle); 1734 + spin_lock_irqsave(&ioc->raid_device_lock, flags); 1748 1735 raid_device = _scsih_raid_device_find_by_handle(ioc, handle); 1749 1736 if (raid_device) 1750 1737 raid_device->direct_io_enabled = 0; 1738 + spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 1751 1739 } 1752 1740 return; 1753 1741 } ··· 1854 1838 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, 1855 1839 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, 1856 1840 vol_pg0->PhysDisk[count].PhysDiskNum) || 1857 - pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) { 1841 + le16_to_cpu(pd_pg0.DevHandle) == 1842 + MPT2SAS_INVALID_DEVICE_HANDLE) { 1858 1843 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " 1859 1844 "disabled for the drive with handle(0x%04x) member" 1860 1845 "handle retrieval failed for member number=%d\n", ··· 1985 1968 u8 ssp_target = 0; 1986 1969 char *ds = ""; 1987 1970 char *r_level = ""; 1971 + u16 handle, volume_handle = 0; 1972 + u64 volume_wwid = 0; 1988 1973 1989 1974 qdepth = 1; 1990 1975 sas_device_priv_data = sdev->hostdata; 1991 1976 sas_device_priv_data->configured_lun = 1; 1992 1977 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; 1993 1978 sas_target_priv_data = sas_device_priv_data->sas_target; 1979 + handle = sas_target_priv_data->handle; 1994 1980 1995 1981 /* raid volume handling */ 1996 1982 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { 1997 1983 1998 1984 spin_lock_irqsave(&ioc->raid_device_lock, flags); 1999 - raid_device = _scsih_raid_device_find_by_handle(ioc, 2000 - sas_target_priv_data->handle); 1985 + raid_device = _scsih_raid_device_find_by_handle(ioc, handle); 2001 1986 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 2002 1987 if (!raid_device) { 2003 1988 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT ··· 2007 1988 __LINE__, __func__)); 2008 1989 return 1; 2009 1990 } 2010 - 2011 - _scsih_get_volume_capabilities(ioc, raid_device); 2012 1991 2013 1992 if (_scsih_get_volume_capabilities(ioc, raid_device)) { 2014 1993 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT ··· 2075 2058 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); 2076 2059 /* raid transport support */ 2077 2060 if (!ioc->is_warpdrive) 2078 - _scsih_set_level(sdev, raid_device); 2061 + _scsih_set_level(sdev, raid_device->volume_type); 2079 2062 return 0; 2080 2063 } 2081 2064 2082 2065 /* non-raid handling */ 2066 + if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { 2067 + if (mpt2sas_config_get_volume_handle(ioc, handle, 2068 + &volume_handle)) { 2069 + dfailprintk(ioc, printk(MPT2SAS_WARN_FMT 2070 + "failure at %s:%d/%s()!\n", ioc->name, 2071 + __FILE__, __LINE__, __func__)); 2072 + return 1; 2073 + } 2074 + if (volume_handle && mpt2sas_config_get_volume_wwid(ioc, 2075 + volume_handle, &volume_wwid)) { 2076 + dfailprintk(ioc, printk(MPT2SAS_WARN_FMT 2077 + "failure at %s:%d/%s()!\n", ioc->name, 2078 + __FILE__, __LINE__, __func__)); 2079 + return 1; 2080 + } 2081 + } 2082 + 2083 2083 spin_lock_irqsave(&ioc->sas_device_lock, flags); 2084 2084 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 2085 2085 sas_device_priv_data->sas_target->sas_address); 2086 - spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 2087 - if (sas_device) { 2088 - if (sas_target_priv_data->flags & 2089 - MPT_TARGET_FLAGS_RAID_COMPONENT) { 2090 - if (mpt2sas_config_get_volume_handle(ioc, 2091 - sas_device->handle, &sas_device->volume_handle)) { 2092 - dfailprintk(ioc, printk(MPT2SAS_WARN_FMT 2093 - "failure at %s:%d/%s()!\n", ioc->name, 2094 - __FILE__, __LINE__, __func__)); 2095 - return 1; 2096 - } 2097 - if (sas_device->volume_handle && 2098 - mpt2sas_config_get_volume_wwid(ioc, 2099 - sas_device->volume_handle, 2100 - &sas_device->volume_wwid)) { 2101 - dfailprintk(ioc, printk(MPT2SAS_WARN_FMT 2102 - "failure at %s:%d/%s()!\n", ioc->name, 2103 - __FILE__, __LINE__, __func__)); 2104 - return 1; 2105 - } 2106 - } 2107 - if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { 2108 - qdepth = MPT2SAS_SAS_QUEUE_DEPTH; 2109 - ssp_target = 1; 2110 - ds = "SSP"; 2111 - } else { 2112 - qdepth = MPT2SAS_SATA_QUEUE_DEPTH; 2113 - if (sas_device->device_info & 2114 - MPI2_SAS_DEVICE_INFO_STP_TARGET) 2115 - ds = "STP"; 2116 - else if (sas_device->device_info & 2117 - MPI2_SAS_DEVICE_INFO_SATA_DEVICE) 2118 - ds = "SATA"; 2119 - } 2120 - 2121 - sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " 2122 - "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", 2123 - ds, sas_device->handle, 2124 - (unsigned long long)sas_device->sas_address, 2125 - sas_device->phy, 2126 - (unsigned long long)sas_device->device_name); 2127 - sdev_printk(KERN_INFO, sdev, "%s: " 2128 - "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, 2129 - (unsigned long long) sas_device->enclosure_logical_id, 2130 - sas_device->slot); 2131 - 2132 - if (!ssp_target) 2133 - _scsih_display_sata_capabilities(ioc, sas_device, sdev); 2134 - } else { 2086 + if (!sas_device) { 2087 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 2135 2088 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT 2136 - "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, 2137 - __func__)); 2089 + "failure at %s:%d/%s()!\n", ioc->name, __FILE__, 2090 + __LINE__, __func__)); 2138 2091 return 1; 2139 2092 } 2093 + sas_device->volume_handle = volume_handle; 2094 + sas_device->volume_wwid = volume_wwid; 2095 + if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { 2096 + qdepth = MPT2SAS_SAS_QUEUE_DEPTH; 2097 + ssp_target = 1; 2098 + ds = "SSP"; 2099 + } else { 2100 + qdepth = MPT2SAS_SATA_QUEUE_DEPTH; 2101 + if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) 2102 + ds = "STP"; 2103 + else if (sas_device->device_info & 2104 + MPI2_SAS_DEVICE_INFO_SATA_DEVICE) 2105 + ds = "SATA"; 2106 + } 2107 + sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " 2108 + "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", 2109 + ds, sas_device->handle, 2110 + (unsigned long long)sas_device->sas_address, 2111 + sas_device->phy, 2112 + (unsigned long long)sas_device->device_name); 2113 + sdev_printk(KERN_INFO, sdev, "%s: " 2114 + "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, 2115 + (unsigned long long) sas_device->enclosure_logical_id, 2116 + sas_device->slot); 2117 + 2118 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 2119 + if (!ssp_target) 2120 + _scsih_display_sata_capabilities(ioc, handle, sdev); 2121 + 2140 2122 2141 2123 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); 2142 2124 ··· 2915 2899 * During device pull we need to appropiately set the sdev state. 2916 2900 */ 2917 2901 static void 2918 - _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) 2902 + _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) 2919 2903 { 2920 2904 struct MPT2SAS_DEVICE *sas_device_priv_data; 2921 2905 struct scsi_device *sdev; ··· 2926 2910 continue; 2927 2911 if (!sas_device_priv_data->block) 2928 2912 continue; 2929 - if (sas_device_priv_data->sas_target->handle == handle) { 2913 + if (sas_device_priv_data->sas_target->sas_address == 2914 + sas_address) { 2930 2915 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, 2931 2916 MPT2SAS_INFO_FMT "SDEV_RUNNING: " 2932 - "handle(0x%04x)\n", ioc->name, handle)); 2917 + "sas address(0x%016llx)\n", ioc->name, 2918 + (unsigned long long)sas_address)); 2933 2919 sas_device_priv_data->block = 0; 2934 2920 scsi_internal_device_unblock(sdev); 2935 2921 } ··· 3024 3006 sas_device = 3025 3007 mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 3026 3008 mpt2sas_port->remote_identify.sas_address); 3009 + if (sas_device) 3010 + set_bit(sas_device->handle, 3011 + ioc->blocking_handles); 3027 3012 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 3028 - if (!sas_device) 3029 - continue; 3030 - _scsih_block_io_device(ioc, sas_device->handle); 3031 3013 } 3032 3014 } 3033 3015 ··· 3038 3020 SAS_EDGE_EXPANDER_DEVICE || 3039 3021 mpt2sas_port->remote_identify.device_type == 3040 3022 SAS_FANOUT_EXPANDER_DEVICE) { 3041 - 3042 - spin_lock_irqsave(&ioc->sas_node_lock, flags); 3043 3023 expander_sibling = 3044 3024 mpt2sas_scsih_expander_find_by_sas_address( 3045 3025 ioc, mpt2sas_port->remote_identify.sas_address); 3046 - spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 3047 3026 _scsih_block_io_to_children_attached_to_ex(ioc, 3048 3027 expander_sibling); 3049 3028 } ··· 3139 3124 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: " 3140 3125 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle, 3141 3126 (unsigned long long)sas_address)); 3142 - _scsih_ublock_io_device(ioc, handle); 3127 + _scsih_ublock_io_device(ioc, sas_address); 3143 3128 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; 3144 3129 } 3145 3130 ··· 3189 3174 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, 3190 3175 u8 msix_index, u32 reply) 3191 3176 { 3192 - #ifdef CONFIG_SCSI_MPT2SAS_LOGGING 3193 3177 Mpi2SasIoUnitControlReply_t *mpi_reply = 3194 3178 mpt2sas_base_get_reply_virt_addr(ioc, reply); 3195 - #endif 3196 - dewtprintk(ioc, printk(MPT2SAS_INFO_FMT 3197 - "sc_complete:handle(0x%04x), (open) " 3198 - "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", 3199 - ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, 3200 - le16_to_cpu(mpi_reply->IOCStatus), 3201 - le32_to_cpu(mpi_reply->IOCLogInfo))); 3179 + if (likely(mpi_reply)) { 3180 + dewtprintk(ioc, printk(MPT2SAS_INFO_FMT 3181 + "sc_complete:handle(0x%04x), (open) " 3182 + "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", 3183 + ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, 3184 + le16_to_cpu(mpi_reply->IOCStatus), 3185 + le32_to_cpu(mpi_reply->IOCLogInfo))); 3186 + } else { 3187 + printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", 3188 + ioc->name, __FILE__, __LINE__, __func__); 3189 + } 3202 3190 return 1; 3203 3191 } 3204 3192 ··· 3280 3262 "progress!\n", __func__, ioc->name)); 3281 3263 return 1; 3282 3264 } 3283 - 3265 + if (unlikely(!mpi_reply)) { 3266 + printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", 3267 + ioc->name, __FILE__, __LINE__, __func__); 3268 + return 1; 3269 + } 3284 3270 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); 3285 3271 handle = le16_to_cpu(mpi_request_tm->DevHandle); 3286 3272 if (handle != le16_to_cpu(mpi_reply->DevHandle)) { ··· 3347 3325 "operational\n", __func__, ioc->name)); 3348 3326 return 1; 3349 3327 } 3350 - 3328 + if (unlikely(!mpi_reply)) { 3329 + printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", 3330 + ioc->name, __FILE__, __LINE__, __func__); 3331 + return 1; 3332 + } 3351 3333 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); 3352 3334 handle = le16_to_cpu(mpi_request_tm->DevHandle); 3353 3335 if (handle != le16_to_cpu(mpi_reply->DevHandle)) { ··· 3467 3441 _scsih_block_io_to_children_attached_directly(ioc, event_data); 3468 3442 return; 3469 3443 } 3470 - 3471 - if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING 3472 - || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) { 3444 + if (event_data->ExpStatus == 3445 + MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { 3446 + /* put expander attached devices into blocking state */ 3473 3447 spin_lock_irqsave(&ioc->sas_node_lock, flags); 3474 3448 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, 3475 3449 expander_handle); 3476 - spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 3477 3450 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); 3451 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 3452 + do { 3453 + handle = find_first_bit(ioc->blocking_handles, 3454 + ioc->facts.MaxDevHandle); 3455 + if (handle < ioc->facts.MaxDevHandle) 3456 + _scsih_block_io_device(ioc, handle); 3457 + } while (test_and_clear_bit(handle, ioc->blocking_handles)); 3478 3458 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) 3479 3459 _scsih_block_io_to_children_attached_directly(ioc, event_data); 3480 3460 ··· 4478 4446 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { 4479 4447 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); 4480 4448 ioc->scsi_lookup[smid - 1].scmd = scmd; 4481 - spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 4482 4449 _scsih_scsi_direct_io_set(ioc, smid, 0); 4450 + spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 4483 4451 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); 4484 4452 mpi_request->DevHandle = 4485 4453 cpu_to_le16(sas_device_priv_data->sas_target->handle); ··· 5052 5020 spin_lock_irqsave(&ioc->sas_node_lock, flags); 5053 5021 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, 5054 5022 sas_address); 5055 - if (!sas_expander) { 5056 - spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 5057 - return; 5058 - } 5059 - list_del(&sas_expander->list); 5023 + if (sas_expander) 5024 + list_del(&sas_expander->list); 5060 5025 spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 5061 - _scsih_expander_node_remove(ioc, sas_expander); 5026 + if (sas_expander) 5027 + _scsih_expander_node_remove(ioc, sas_expander); 5062 5028 } 5063 5029 5064 5030 /** ··· 5136 5106 struct MPT2SAS_TARGET *sas_target_priv_data; 5137 5107 u32 device_info; 5138 5108 5109 + 5139 5110 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, 5140 5111 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) 5141 5112 return; ··· 5170 5139 sas_target_priv_data->handle = handle; 5171 5140 sas_device->handle = handle; 5172 5141 } 5173 - spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5174 5142 5175 5143 /* check if device is present */ 5176 5144 if (!(le16_to_cpu(sas_device_pg0.Flags) & 5177 5145 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { 5178 5146 printk(MPT2SAS_ERR_FMT "device is not present " 5179 5147 "handle(0x%04x), flags!!!\n", ioc->name, handle); 5148 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5180 5149 return; 5181 5150 } 5182 5151 5183 5152 /* check if there were any issues with discovery */ 5184 5153 if (_scsih_check_access_status(ioc, sas_address, handle, 5185 - sas_device_pg0.AccessStatus)) 5154 + sas_device_pg0.AccessStatus)) { 5155 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5186 5156 return; 5187 - _scsih_ublock_io_device(ioc, handle); 5157 + } 5158 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5159 + _scsih_ublock_io_device(ioc, sas_address); 5188 5160 5189 5161 } 5190 5162 ··· 5314 5280 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, 5315 5281 struct _sas_device *sas_device) 5316 5282 { 5317 - struct _sas_device sas_device_backup; 5318 5283 struct MPT2SAS_TARGET *sas_target_priv_data; 5319 - 5320 - if (!sas_device) 5321 - return; 5322 - 5323 - memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device)); 5324 - _scsih_sas_device_remove(ioc, sas_device); 5325 5284 5326 5285 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: " 5327 5286 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, 5328 - sas_device_backup.handle, (unsigned long long) 5329 - sas_device_backup.sas_address)); 5287 + sas_device->handle, (unsigned long long) 5288 + sas_device->sas_address)); 5330 5289 5331 - if (sas_device_backup.starget && sas_device_backup.starget->hostdata) { 5332 - sas_target_priv_data = sas_device_backup.starget->hostdata; 5290 + if (sas_device->starget && sas_device->starget->hostdata) { 5291 + sas_target_priv_data = sas_device->starget->hostdata; 5333 5292 sas_target_priv_data->deleted = 1; 5334 - _scsih_ublock_io_device(ioc, sas_device_backup.handle); 5293 + _scsih_ublock_io_device(ioc, sas_device->sas_address); 5335 5294 sas_target_priv_data->handle = 5336 5295 MPT2SAS_INVALID_DEVICE_HANDLE; 5337 5296 } 5338 5297 5339 - _scsih_ublock_io_device(ioc, sas_device_backup.handle); 5340 - 5341 5298 if (!ioc->hide_drives) 5342 5299 mpt2sas_transport_port_remove(ioc, 5343 - sas_device_backup.sas_address, 5344 - sas_device_backup.sas_address_parent); 5300 + sas_device->sas_address, 5301 + sas_device->sas_address_parent); 5345 5302 5346 5303 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" 5347 - "(0x%016llx)\n", ioc->name, sas_device_backup.handle, 5348 - (unsigned long long) sas_device_backup.sas_address); 5304 + "(0x%016llx)\n", ioc->name, sas_device->handle, 5305 + (unsigned long long) sas_device->sas_address); 5349 5306 5350 5307 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: " 5351 5308 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, 5352 - sas_device_backup.handle, (unsigned long long) 5353 - sas_device_backup.sas_address)); 5309 + sas_device->handle, (unsigned long long) 5310 + sas_device->sas_address)); 5311 + kfree(sas_device); 5312 + } 5313 + /** 5314 + * _scsih_device_remove_by_handle - removing device object by handle 5315 + * @ioc: per adapter object 5316 + * @handle: device handle 5317 + * 5318 + * Return nothing. 5319 + */ 5320 + static void 5321 + _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) 5322 + { 5323 + struct _sas_device *sas_device; 5324 + unsigned long flags; 5325 + 5326 + if (ioc->shost_recovery) 5327 + return; 5328 + 5329 + spin_lock_irqsave(&ioc->sas_device_lock, flags); 5330 + sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 5331 + if (sas_device) 5332 + list_del(&sas_device->list); 5333 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5334 + if (sas_device) 5335 + _scsih_remove_device(ioc, sas_device); 5354 5336 } 5355 5337 5356 5338 /** 5357 - * mpt2sas_device_remove - removing device object 5339 + * mpt2sas_device_remove_by_sas_address - removing device object by sas address 5358 5340 * @ioc: per adapter object 5359 - * @sas_address: expander sas_address 5341 + * @sas_address: device sas_address 5360 5342 * 5361 5343 * Return nothing. 5362 5344 */ 5363 5345 void 5364 - mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) 5346 + mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, 5347 + u64 sas_address) 5365 5348 { 5366 5349 struct _sas_device *sas_device; 5367 5350 unsigned long flags; ··· 5389 5338 spin_lock_irqsave(&ioc->sas_device_lock, flags); 5390 5339 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 5391 5340 sas_address); 5392 - if (!sas_device) { 5393 - spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5394 - return; 5395 - } 5341 + if (sas_device) 5342 + list_del(&sas_device->list); 5396 5343 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5397 - _scsih_remove_device(ioc, sas_device); 5344 + if (sas_device) 5345 + _scsih_remove_device(ioc, sas_device); 5398 5346 } 5399 - 5400 5347 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING 5401 5348 /** 5402 5349 * _scsih_sas_topology_change_event_debug - debug for topology event ··· 5491 5442 u16 reason_code; 5492 5443 u8 phy_number, max_phys; 5493 5444 struct _sas_node *sas_expander; 5494 - struct _sas_device *sas_device; 5495 5445 u64 sas_address; 5496 5446 unsigned long flags; 5497 5447 u8 link_rate, prev_link_rate; ··· 5525 5477 spin_lock_irqsave(&ioc->sas_node_lock, flags); 5526 5478 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, 5527 5479 parent_handle); 5528 - spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 5529 5480 if (sas_expander) { 5530 5481 sas_address = sas_expander->sas_address; 5531 5482 max_phys = sas_expander->num_phys; 5532 5483 } else if (parent_handle < ioc->sas_hba.num_phys) { 5533 5484 sas_address = ioc->sas_hba.sas_address; 5534 5485 max_phys = ioc->sas_hba.num_phys; 5535 - } else 5486 + } else { 5487 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 5536 5488 return; 5489 + } 5490 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 5537 5491 5538 5492 /* handle siblings events */ 5539 5493 for (i = 0; i < event_data->NumEntries; i++) { ··· 5590 5540 break; 5591 5541 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: 5592 5542 5593 - spin_lock_irqsave(&ioc->sas_device_lock, flags); 5594 - sas_device = _scsih_sas_device_find_by_handle(ioc, 5595 - handle); 5596 - if (!sas_device) { 5597 - spin_unlock_irqrestore(&ioc->sas_device_lock, 5598 - flags); 5599 - break; 5600 - } 5601 - spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5602 - _scsih_remove_device(ioc, sas_device); 5543 + _scsih_device_remove_by_handle(ioc, handle); 5603 5544 break; 5604 5545 } 5605 5546 } ··· 5713 5672 sas_address = le64_to_cpu(event_data->SASAddress); 5714 5673 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 5715 5674 sas_address); 5716 - spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5717 5675 5718 - if (!sas_device || !sas_device->starget) 5676 + if (!sas_device || !sas_device->starget) { 5677 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5719 5678 return; 5679 + } 5720 5680 5721 5681 target_priv_data = sas_device->starget->hostdata; 5722 - if (!target_priv_data) 5682 + if (!target_priv_data) { 5683 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5723 5684 return; 5685 + } 5724 5686 5725 5687 if (event_data->ReasonCode == 5726 5688 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) 5727 5689 target_priv_data->tm_busy = 1; 5728 5690 else 5729 5691 target_priv_data->tm_busy = 0; 5692 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5730 5693 } 5731 5694 5732 5695 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING ··· 5995 5950 } 5996 5951 5997 5952 /** 5998 - * _scsih_reprobe_target - reprobing target 5999 - * @starget: scsi target struct 6000 - * @no_uld_attach: sdev->no_uld_attach flag setting 6001 - * 6002 - * Note: no_uld_attach flag determines whether the disk device is attached 6003 - * to block layer. A value of `1` means to not attach. 6004 - **/ 6005 - static void 6006 - _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach) 6007 - { 6008 - struct MPT2SAS_TARGET *sas_target_priv_data; 6009 - 6010 - if (starget == NULL) 6011 - return; 6012 - sas_target_priv_data = starget->hostdata; 6013 - if (no_uld_attach) 6014 - sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 6015 - else 6016 - sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; 6017 - 6018 - starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL, 6019 - _scsih_reprobe_lun); 6020 - } 6021 - /** 6022 5953 * _scsih_sas_volume_add - add new volume 6023 5954 * @ioc: per adapter object 6024 5955 * @element: IR config element data ··· 6045 6024 raid_device->id, 0); 6046 6025 if (rc) 6047 6026 _scsih_raid_device_remove(ioc, raid_device); 6048 - } else 6027 + } else { 6028 + spin_lock_irqsave(&ioc->raid_device_lock, flags); 6049 6029 _scsih_determine_boot_device(ioc, raid_device, 1); 6030 + spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 6031 + } 6050 6032 } 6051 6033 6052 6034 /** ··· 6066 6042 struct _raid_device *raid_device; 6067 6043 unsigned long flags; 6068 6044 struct MPT2SAS_TARGET *sas_target_priv_data; 6045 + struct scsi_target *starget = NULL; 6069 6046 6070 6047 spin_lock_irqsave(&ioc->raid_device_lock, flags); 6071 6048 raid_device = _scsih_raid_device_find_by_handle(ioc, handle); 6072 - spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 6073 - if (!raid_device) 6074 - return; 6075 - if (raid_device->starget) { 6076 - sas_target_priv_data = raid_device->starget->hostdata; 6077 - sas_target_priv_data->deleted = 1; 6078 - scsi_remove_target(&raid_device->starget->dev); 6049 + if (raid_device) { 6050 + if (raid_device->starget) { 6051 + starget = raid_device->starget; 6052 + sas_target_priv_data = starget->hostdata; 6053 + sas_target_priv_data->deleted = 1; 6054 + } 6055 + printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" 6056 + "(0x%016llx)\n", ioc->name, raid_device->handle, 6057 + (unsigned long long) raid_device->wwid); 6058 + list_del(&raid_device->list); 6059 + kfree(raid_device); 6079 6060 } 6080 - printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" 6081 - "(0x%016llx)\n", ioc->name, raid_device->handle, 6082 - (unsigned long long) raid_device->wwid); 6083 - _scsih_raid_device_remove(ioc, raid_device); 6061 + spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 6062 + if (starget) 6063 + scsi_remove_target(&starget->dev); 6084 6064 } 6085 6065 6086 6066 /** ··· 6100 6072 Mpi2EventIrConfigElement_t *element) 6101 6073 { 6102 6074 struct _sas_device *sas_device; 6075 + struct scsi_target *starget = NULL; 6076 + struct MPT2SAS_TARGET *sas_target_priv_data; 6103 6077 unsigned long flags; 6104 6078 u16 handle = le16_to_cpu(element->PhysDiskDevHandle); 6105 6079 6106 6080 spin_lock_irqsave(&ioc->sas_device_lock, flags); 6107 6081 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 6082 + if (sas_device) { 6083 + sas_device->volume_handle = 0; 6084 + sas_device->volume_wwid = 0; 6085 + clear_bit(handle, ioc->pd_handles); 6086 + if (sas_device->starget && sas_device->starget->hostdata) { 6087 + starget = sas_device->starget; 6088 + sas_target_priv_data = starget->hostdata; 6089 + sas_target_priv_data->flags &= 6090 + ~MPT_TARGET_FLAGS_RAID_COMPONENT; 6091 + } 6092 + } 6108 6093 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 6109 6094 if (!sas_device) 6110 6095 return; 6111 6096 6112 6097 /* exposing raid component */ 6113 - sas_device->volume_handle = 0; 6114 - sas_device->volume_wwid = 0; 6115 - clear_bit(handle, ioc->pd_handles); 6116 - _scsih_reprobe_target(sas_device->starget, 0); 6098 + if (starget) 6099 + starget_for_each_device(starget, NULL, _scsih_reprobe_lun); 6117 6100 } 6118 6101 6119 6102 /** ··· 6140 6101 Mpi2EventIrConfigElement_t *element) 6141 6102 { 6142 6103 struct _sas_device *sas_device; 6104 + struct scsi_target *starget = NULL; 6105 + struct MPT2SAS_TARGET *sas_target_priv_data; 6143 6106 unsigned long flags; 6144 6107 u16 handle = le16_to_cpu(element->PhysDiskDevHandle); 6108 + u16 volume_handle = 0; 6109 + u64 volume_wwid = 0; 6110 + 6111 + mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle); 6112 + if (volume_handle) 6113 + mpt2sas_config_get_volume_wwid(ioc, volume_handle, 6114 + &volume_wwid); 6145 6115 6146 6116 spin_lock_irqsave(&ioc->sas_device_lock, flags); 6147 6117 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 6118 + if (sas_device) { 6119 + set_bit(handle, ioc->pd_handles); 6120 + if (sas_device->starget && sas_device->starget->hostdata) { 6121 + starget = sas_device->starget; 6122 + sas_target_priv_data = starget->hostdata; 6123 + sas_target_priv_data->flags |= 6124 + MPT_TARGET_FLAGS_RAID_COMPONENT; 6125 + sas_device->volume_handle = volume_handle; 6126 + sas_device->volume_wwid = volume_wwid; 6127 + } 6128 + } 6148 6129 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 6149 6130 if (!sas_device) 6150 6131 return; 6151 6132 6152 6133 /* hiding raid component */ 6153 - mpt2sas_config_get_volume_handle(ioc, handle, 6154 - &sas_device->volume_handle); 6155 - mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle, 6156 - &sas_device->volume_wwid); 6157 - set_bit(handle, ioc->pd_handles); 6158 - _scsih_reprobe_target(sas_device->starget, 1); 6159 - 6134 + if (starget) 6135 + starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); 6160 6136 } 6161 6137 6162 6138 /** ··· 6186 6132 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, 6187 6133 Mpi2EventIrConfigElement_t *element) 6188 6134 { 6189 - struct _sas_device *sas_device; 6190 - unsigned long flags; 6191 6135 u16 handle = le16_to_cpu(element->PhysDiskDevHandle); 6192 6136 6193 - spin_lock_irqsave(&ioc->sas_device_lock, flags); 6194 - sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 6195 - spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 6196 - if (!sas_device) 6197 - return; 6198 - _scsih_remove_device(ioc, sas_device); 6137 + _scsih_device_remove_by_handle(ioc, handle); 6199 6138 } 6200 6139 6201 6140 /** ··· 6630 6583 /* code added for raid transport support */ 6631 6584 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { 6632 6585 6633 - handle = le16_to_cpu(event_data->VolDevHandle); 6634 - 6635 6586 spin_lock_irqsave(&ioc->raid_device_lock, flags); 6587 + handle = le16_to_cpu(event_data->VolDevHandle); 6636 6588 raid_device = _scsih_raid_device_find_by_handle(ioc, handle); 6637 - spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 6638 - 6639 - if (!raid_device) 6640 - return; 6641 - 6642 - if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) 6589 + if (raid_device) 6643 6590 raid_device->percent_complete = 6644 6591 event_data->PercentComplete; 6592 + spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 6645 6593 } 6646 6594 } 6647 6595 ··· 6803 6761 * required data for Direct IO 6804 6762 */ 6805 6763 _scsih_init_warpdrive_properties(ioc, raid_device); 6806 - if (raid_device->handle == handle) 6764 + spin_lock_irqsave(&ioc->raid_device_lock, flags); 6765 + if (raid_device->handle == handle) { 6766 + spin_unlock_irqrestore(&ioc->raid_device_lock, 6767 + flags); 6807 6768 return; 6769 + } 6808 6770 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", 6809 6771 raid_device->handle); 6810 6772 raid_device->handle = handle; 6811 6773 if (sas_target_priv_data) 6812 6774 sas_target_priv_data->handle = handle; 6775 + spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 6813 6776 return; 6814 6777 } 6815 6778 } ··· 6986 6939 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc) 6987 6940 { 6988 6941 struct _sas_device *sas_device, *sas_device_next; 6989 - struct _sas_node *sas_expander; 6942 + struct _sas_node *sas_expander, *sas_expander_next; 6990 6943 struct _raid_device *raid_device, *raid_device_next; 6944 + struct list_head tmp_list; 6945 + unsigned long flags; 6991 6946 6992 6947 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n", 6993 6948 ioc->name); 6994 6949 6950 + /* removing unresponding end devices */ 6951 + printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n", 6952 + ioc->name); 6995 6953 list_for_each_entry_safe(sas_device, sas_device_next, 6996 6954 &ioc->sas_device_list, list) { 6997 - if (sas_device->responding) { 6955 + if (!sas_device->responding) 6956 + mpt2sas_device_remove_by_sas_address(ioc, 6957 + sas_device->sas_address); 6958 + else 6998 6959 sas_device->responding = 0; 6999 - continue; 7000 - } 7001 - if (sas_device->starget) 7002 - starget_printk(KERN_INFO, sas_device->starget, 7003 - "removing: handle(0x%04x), sas_addr(0x%016llx), " 7004 - "enclosure logical id(0x%016llx), slot(%d)\n", 7005 - sas_device->handle, 7006 - (unsigned long long)sas_device->sas_address, 7007 - (unsigned long long) 7008 - sas_device->enclosure_logical_id, 7009 - sas_device->slot); 7010 - _scsih_remove_device(ioc, sas_device); 7011 6960 } 7012 6961 7013 - if (!ioc->ir_firmware) 7014 - goto retry_expander_search; 7015 - 7016 - list_for_each_entry_safe(raid_device, raid_device_next, 7017 - &ioc->raid_device_list, list) { 7018 - if (raid_device->responding) { 7019 - raid_device->responding = 0; 7020 - continue; 6962 + /* removing unresponding volumes */ 6963 + if (ioc->ir_firmware) { 6964 + printk(MPT2SAS_INFO_FMT "removing unresponding devices: " 6965 + "volumes\n", ioc->name); 6966 + list_for_each_entry_safe(raid_device, raid_device_next, 6967 + &ioc->raid_device_list, list) { 6968 + if (!raid_device->responding) 6969 + _scsih_sas_volume_delete(ioc, 6970 + raid_device->handle); 6971 + else 6972 + raid_device->responding = 0; 7021 6973 } 7022 - if (raid_device->starget) { 7023 - starget_printk(KERN_INFO, raid_device->starget, 7024 - "removing: handle(0x%04x), wwid(0x%016llx)\n", 7025 - raid_device->handle, 7026 - (unsigned long long)raid_device->wwid); 7027 - scsi_remove_target(&raid_device->starget->dev); 7028 - } 7029 - _scsih_raid_device_remove(ioc, raid_device); 7030 6974 } 7031 - 7032 - retry_expander_search: 7033 - sas_expander = NULL; 7034 - list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { 7035 - if (sas_expander->responding) { 6975 + /* removing unresponding expanders */ 6976 + printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n", 6977 + ioc->name); 6978 + spin_lock_irqsave(&ioc->sas_node_lock, flags); 6979 + INIT_LIST_HEAD(&tmp_list); 6980 + list_for_each_entry_safe(sas_expander, sas_expander_next, 6981 + &ioc->sas_expander_list, list) { 6982 + if (!sas_expander->responding) 6983 + list_move_tail(&sas_expander->list, &tmp_list); 6984 + else 7036 6985 sas_expander->responding = 0; 7037 - continue; 7038 - } 7039 - mpt2sas_expander_remove(ioc, sas_expander->sas_address); 7040 - goto retry_expander_search; 6986 + } 6987 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 6988 + list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, 6989 + list) { 6990 + list_del(&sas_expander->list); 6991 + _scsih_expander_node_remove(ioc, sas_expander); 7041 6992 } 7042 6993 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n", 7043 6994 ioc->name); ··· 7088 7043 struct _sas_device *sas_device; 7089 7044 struct _sas_node *expander_device; 7090 7045 static struct _raid_device *raid_device; 7046 + unsigned long flags; 7091 7047 7092 7048 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name); 7093 7049 ··· 7103 7057 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) 7104 7058 break; 7105 7059 handle = le16_to_cpu(expander_pg0.DevHandle); 7060 + spin_lock_irqsave(&ioc->sas_node_lock, flags); 7106 7061 expander_device = mpt2sas_scsih_expander_find_by_sas_address( 7107 7062 ioc, le64_to_cpu(expander_pg0.SASAddress)); 7063 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 7108 7064 if (expander_device) 7109 7065 _scsih_refresh_expander_links(ioc, expander_device, 7110 7066 handle); ··· 7128 7080 break; 7129 7081 phys_disk_num = pd_pg0.PhysDiskNum; 7130 7082 handle = le16_to_cpu(pd_pg0.DevHandle); 7083 + spin_lock_irqsave(&ioc->sas_device_lock, flags); 7131 7084 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 7085 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 7132 7086 if (sas_device) 7133 7087 continue; 7134 7088 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, ··· 7157 7107 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) 7158 7108 break; 7159 7109 handle = le16_to_cpu(volume_pg1.DevHandle); 7110 + spin_lock_irqsave(&ioc->raid_device_lock, flags); 7160 7111 raid_device = _scsih_raid_device_find_by_wwid(ioc, 7161 7112 le64_to_cpu(volume_pg1.WWID)); 7113 + spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 7162 7114 if (raid_device) 7163 7115 continue; 7164 7116 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, ··· 7192 7140 if (!(_scsih_is_end_device( 7193 7141 le32_to_cpu(sas_device_pg0.DeviceInfo)))) 7194 7142 continue; 7143 + spin_lock_irqsave(&ioc->sas_device_lock, flags); 7195 7144 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 7196 7145 le64_to_cpu(sas_device_pg0.SASAddress)); 7146 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 7197 7147 if (sas_device) 7198 7148 continue; 7199 7149 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); ··· 7289 7235 7290 7236 switch (fw_event->event) { 7291 7237 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES: 7292 - while (scsi_host_in_recovery(ioc->shost)) 7238 + while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) 7293 7239 ssleep(1); 7294 7240 _scsih_remove_unresponding_sas_devices(ioc); 7295 7241 _scsih_scan_for_devices_after_reset(ioc); ··· 7367 7313 return 1; 7368 7314 7369 7315 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); 7316 + 7317 + if (unlikely(!mpi_reply)) { 7318 + printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", 7319 + ioc->name, __FILE__, __LINE__, __func__); 7320 + return 1; 7321 + } 7322 + 7370 7323 event = le16_to_cpu(mpi_reply->Event); 7371 7324 7372 7325 switch (event) { ··· 7414 7353 case MPI2_EVENT_LOG_ENTRY_ADDED: 7415 7354 { 7416 7355 Mpi2EventDataLogEntryAdded_t *log_entry; 7417 - u32 *log_code; 7356 + __le32 *log_code; 7418 7357 7419 7358 if (!ioc->is_warpdrive) 7420 7359 break; 7421 7360 7422 7361 log_entry = (Mpi2EventDataLogEntryAdded_t *) 7423 7362 mpi_reply->EventData; 7424 - log_code = (u32 *)log_entry->LogData; 7363 + log_code = (__le32 *)log_entry->LogData; 7425 7364 7426 7365 if (le16_to_cpu(log_entry->LogEntryQualifier) 7427 7366 != MPT2_WARPDRIVE_LOGENTRY) ··· 7548 7487 return; 7549 7488 if (mpt2sas_port->remote_identify.device_type == 7550 7489 SAS_END_DEVICE) 7551 - mpt2sas_device_remove(ioc, 7490 + mpt2sas_device_remove_by_sas_address(ioc, 7552 7491 mpt2sas_port->remote_identify.sas_address); 7553 7492 else if (mpt2sas_port->remote_identify.device_type == 7554 7493 SAS_EDGE_EXPANDER_DEVICE || ··· 7722 7661 &ioc->sas_hba.sas_port_list, port_list) { 7723 7662 if (mpt2sas_port->remote_identify.device_type == 7724 7663 SAS_END_DEVICE) 7725 - mpt2sas_device_remove(ioc, 7664 + mpt2sas_device_remove_by_sas_address(ioc, 7726 7665 mpt2sas_port->remote_identify.sas_address); 7727 7666 else if (mpt2sas_port->remote_identify.device_type == 7728 7667 SAS_EDGE_EXPANDER_DEVICE || ··· 7794 7733 if (rc) 7795 7734 _scsih_raid_device_remove(ioc, raid_device); 7796 7735 } else { 7736 + spin_lock_irqsave(&ioc->sas_device_lock, flags); 7797 7737 sas_device = device; 7798 7738 handle = sas_device->handle; 7799 7739 sas_address_parent = sas_device->sas_address_parent; 7800 7740 sas_address = sas_device->sas_address; 7801 - spin_lock_irqsave(&ioc->sas_device_lock, flags); 7802 7741 list_move_tail(&sas_device->list, &ioc->sas_device_list); 7803 7742 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 7804 7743 ··· 8122 8061 out_thread_fail: 8123 8062 list_del(&ioc->list); 8124 8063 scsi_remove_host(shost); 8125 - scsi_host_put(shost); 8126 8064 out_add_shost_fail: 8065 + scsi_host_put(shost); 8127 8066 return -ENODEV; 8128 8067 } 8129 8068
+194 -49
drivers/scsi/mpt2sas/mpt2sas_transport.c
··· 163 163 return -EIO; 164 164 } 165 165 166 - memset(identify, 0, sizeof(*identify)); 166 + memset(identify, 0, sizeof(struct sas_identify)); 167 167 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); 168 168 169 169 /* sas_address */ 170 170 identify->sas_address = le64_to_cpu(sas_device_pg0.SASAddress); 171 + 172 + /* phy number of the parent device this device is linked to */ 173 + identify->phy_identifier = sas_device_pg0.PhyNum; 171 174 172 175 /* device_type */ 173 176 switch (device_info & MPI2_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) { ··· 487 484 488 485 ioc->logging_level |= MPT_DEBUG_TRANSPORT; 489 486 if (device_type == SAS_END_DEVICE) 490 - mpt2sas_device_remove(ioc, sas_address); 487 + mpt2sas_device_remove_by_sas_address(ioc, sas_address); 491 488 else if (device_type == SAS_EDGE_EXPANDER_DEVICE || 492 489 device_type == SAS_FANOUT_EXPANDER_DEVICE) 493 490 mpt2sas_expander_remove(ioc, sas_address); ··· 795 792 spin_lock_irqsave(&ioc->sas_node_lock, flags); 796 793 sas_node = _transport_sas_node_find_by_sas_address(ioc, 797 794 sas_address_parent); 798 - spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 799 - if (!sas_node) 795 + if (!sas_node) { 796 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 800 797 return; 798 + } 801 799 list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list, 802 800 port_list) { 803 801 if (mpt2sas_port->remote_identify.sas_address != sas_address) ··· 808 804 goto out; 809 805 } 810 806 out: 811 - if (!found) 807 + if (!found) { 808 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 812 809 return; 810 + } 813 811 814 812 for (i = 0; i < sas_node->num_phys; i++) { 815 813 if (sas_node->phy[i].remote_identify.sas_address == sas_address) ··· 819 813 sizeof(struct sas_identify)); 820 814 } 821 815 816 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 822 817 list_for_each_entry_safe(mpt2sas_phy, next_phy, 823 818 &mpt2sas_port->phy_list, port_siblings) { 824 819 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) ··· 993 986 994 987 spin_lock_irqsave(&ioc->sas_node_lock, flags); 995 988 sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address); 996 - spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 997 - if (!sas_node) 989 + if (!sas_node) { 990 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 998 991 return; 992 + } 999 993 1000 994 mpt2sas_phy = &sas_node->phy[phy_number]; 1001 995 mpt2sas_phy->attached_handle = handle; 996 + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); 1002 997 if (handle && (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) { 1003 998 _transport_set_identify(ioc, handle, 1004 999 &mpt2sas_phy->remote_identify); ··· 1319 1310 struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); 1320 1311 struct _sas_device *sas_device; 1321 1312 unsigned long flags; 1313 + int rc; 1322 1314 1323 1315 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1324 1316 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 1325 1317 rphy->identify.sas_address); 1318 + if (sas_device) { 1319 + *identifier = sas_device->enclosure_logical_id; 1320 + rc = 0; 1321 + } else { 1322 + *identifier = 0; 1323 + rc = -ENXIO; 1324 + } 1326 1325 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1327 - 1328 - if (!sas_device) 1329 - return -ENXIO; 1330 - 1331 - *identifier = sas_device->enclosure_logical_id; 1332 - return 0; 1326 + return rc; 1333 1327 } 1334 1328 1335 1329 /** ··· 1347 1335 struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); 1348 1336 struct _sas_device *sas_device; 1349 1337 unsigned long flags; 1338 + int rc; 1350 1339 1351 1340 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1352 1341 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 1353 1342 rphy->identify.sas_address); 1343 + if (sas_device) 1344 + rc = sas_device->slot; 1345 + else 1346 + rc = -ENXIO; 1354 1347 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1355 - 1356 - if (!sas_device) 1357 - return -ENXIO; 1358 - 1359 - return sas_device->slot; 1348 + return rc; 1360 1349 } 1361 1350 1362 1351 /* phy control request structure */ ··· 1642 1629 { 1643 1630 struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); 1644 1631 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; 1632 + Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; 1645 1633 Mpi2ConfigReply_t mpi_reply; 1646 1634 u16 ioc_status; 1647 1635 u16 sz; 1648 1636 int rc = 0; 1649 1637 unsigned long flags; 1638 + int i, discovery_active; 1650 1639 1651 1640 spin_lock_irqsave(&ioc->sas_node_lock, flags); 1652 1641 if (_transport_sas_node_find_by_sas_address(ioc, ··· 1666 1651 1667 1652 /* handle hba phys */ 1668 1653 1669 - /* sas_iounit page 1 */ 1654 + /* read sas_iounit page 0 */ 1655 + sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * 1656 + sizeof(Mpi2SasIOUnit0PhyData_t)); 1657 + sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); 1658 + if (!sas_iounit_pg0) { 1659 + printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1660 + ioc->name, __FILE__, __LINE__, __func__); 1661 + rc = -ENOMEM; 1662 + goto out; 1663 + } 1664 + if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, 1665 + sas_iounit_pg0, sz))) { 1666 + printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1667 + ioc->name, __FILE__, __LINE__, __func__); 1668 + rc = -ENXIO; 1669 + goto out; 1670 + } 1671 + ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & 1672 + MPI2_IOCSTATUS_MASK; 1673 + if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { 1674 + printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1675 + ioc->name, __FILE__, __LINE__, __func__); 1676 + rc = -EIO; 1677 + goto out; 1678 + } 1679 + 1680 + /* unable to enable/disable phys when when discovery is active */ 1681 + for (i = 0, discovery_active = 0; i < ioc->sas_hba.num_phys ; i++) { 1682 + if (sas_iounit_pg0->PhyData[i].PortFlags & 1683 + MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) { 1684 + printk(MPT2SAS_ERR_FMT "discovery is active on " 1685 + "port = %d, phy = %d: unable to enable/disable " 1686 + "phys, try again later!\n", ioc->name, 1687 + sas_iounit_pg0->PhyData[i].Port, i); 1688 + discovery_active = 1; 1689 + } 1690 + } 1691 + 1692 + if (discovery_active) { 1693 + rc = -EAGAIN; 1694 + goto out; 1695 + } 1696 + 1697 + /* read sas_iounit page 1 */ 1670 1698 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * 1671 1699 sizeof(Mpi2SasIOUnit1PhyData_t)); 1672 1700 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); ··· 1734 1676 rc = -EIO; 1735 1677 goto out; 1736 1678 } 1737 - 1679 + /* copy Port/PortFlags/PhyFlags from page 0 */ 1680 + for (i = 0; i < ioc->sas_hba.num_phys ; i++) { 1681 + sas_iounit_pg1->PhyData[i].Port = 1682 + sas_iounit_pg0->PhyData[i].Port; 1683 + sas_iounit_pg1->PhyData[i].PortFlags = 1684 + (sas_iounit_pg0->PhyData[i].PortFlags & 1685 + MPI2_SASIOUNIT0_PORTFLAGS_AUTO_PORT_CONFIG); 1686 + sas_iounit_pg1->PhyData[i].PhyFlags = 1687 + (sas_iounit_pg0->PhyData[i].PhyFlags & 1688 + (MPI2_SASIOUNIT0_PHYFLAGS_ZONING_ENABLED + 1689 + MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED)); 1690 + } 1738 1691 if (enable) 1739 1692 sas_iounit_pg1->PhyData[phy->number].PhyFlags 1740 1693 &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE; ··· 1761 1692 1762 1693 out: 1763 1694 kfree(sas_iounit_pg1); 1695 + kfree(sas_iounit_pg0); 1764 1696 return rc; 1765 1697 } 1766 1698 ··· 1898 1828 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); 1899 1829 Mpi2SmpPassthroughRequest_t *mpi_request; 1900 1830 Mpi2SmpPassthroughReply_t *mpi_reply; 1901 - int rc; 1831 + int rc, i; 1902 1832 u16 smid; 1903 1833 u32 ioc_state; 1904 1834 unsigned long timeleft; ··· 1907 1837 u8 issue_reset = 0; 1908 1838 dma_addr_t dma_addr_in = 0; 1909 1839 dma_addr_t dma_addr_out = 0; 1840 + dma_addr_t pci_dma_in = 0; 1841 + dma_addr_t pci_dma_out = 0; 1842 + void *pci_addr_in = NULL; 1843 + void *pci_addr_out = NULL; 1910 1844 u16 wait_state_count; 1911 1845 struct request *rsp = req->next_rq; 1846 + struct bio_vec *bvec = NULL; 1912 1847 1913 1848 if (!rsp) { 1914 1849 printk(MPT2SAS_ERR_FMT "%s: the smp response space is " 1915 1850 "missing\n", ioc->name, __func__); 1916 1851 return -EINVAL; 1917 1852 } 1918 - 1919 - /* do we need to support multiple segments? */ 1920 - if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) { 1921 - printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, " 1922 - "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt, 1923 - blk_rq_bytes(req), rsp->bio->bi_vcnt, blk_rq_bytes(rsp)); 1924 - return -EINVAL; 1925 - } 1926 - 1927 - if (ioc->shost_recovery) { 1853 + if (ioc->shost_recovery || ioc->pci_error_recovery) { 1928 1854 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", 1929 1855 __func__, ioc->name); 1930 1856 return -EFAULT; ··· 1938 1872 } 1939 1873 ioc->transport_cmds.status = MPT2_CMD_PENDING; 1940 1874 1875 + /* Check if the request is split across multiple segments */ 1876 + if (req->bio->bi_vcnt > 1) { 1877 + u32 offset = 0; 1878 + 1879 + /* Allocate memory and copy the request */ 1880 + pci_addr_out = pci_alloc_consistent(ioc->pdev, 1881 + blk_rq_bytes(req), &pci_dma_out); 1882 + if (!pci_addr_out) { 1883 + printk(MPT2SAS_INFO_FMT "%s(): PCI Addr out = NULL\n", 1884 + ioc->name, __func__); 1885 + rc = -ENOMEM; 1886 + goto out; 1887 + } 1888 + 1889 + bio_for_each_segment(bvec, req->bio, i) { 1890 + memcpy(pci_addr_out + offset, 1891 + page_address(bvec->bv_page) + bvec->bv_offset, 1892 + bvec->bv_len); 1893 + offset += bvec->bv_len; 1894 + } 1895 + } else { 1896 + dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio), 1897 + blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL); 1898 + if (!dma_addr_out) { 1899 + printk(MPT2SAS_INFO_FMT "%s(): DMA Addr out = NULL\n", 1900 + ioc->name, __func__); 1901 + rc = -ENOMEM; 1902 + goto free_pci; 1903 + } 1904 + } 1905 + 1906 + /* Check if the response needs to be populated across 1907 + * multiple segments */ 1908 + if (rsp->bio->bi_vcnt > 1) { 1909 + pci_addr_in = pci_alloc_consistent(ioc->pdev, blk_rq_bytes(rsp), 1910 + &pci_dma_in); 1911 + if (!pci_addr_in) { 1912 + printk(MPT2SAS_INFO_FMT "%s(): PCI Addr in = NULL\n", 1913 + ioc->name, __func__); 1914 + rc = -ENOMEM; 1915 + goto unmap; 1916 + } 1917 + } else { 1918 + dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio), 1919 + blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL); 1920 + if (!dma_addr_in) { 1921 + printk(MPT2SAS_INFO_FMT "%s(): DMA Addr in = NULL\n", 1922 + ioc->name, __func__); 1923 + rc = -ENOMEM; 1924 + goto unmap; 1925 + } 1926 + } 1927 + 1941 1928 wait_state_count = 0; 1942 1929 ioc_state = mpt2sas_base_get_iocstate(ioc, 1); 1943 1930 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { ··· 1999 1880 "%s: failed due to ioc not operational\n", 2000 1881 ioc->name, __func__); 2001 1882 rc = -EFAULT; 2002 - goto out; 1883 + goto unmap; 2003 1884 } 2004 1885 ssleep(1); 2005 1886 ioc_state = mpt2sas_base_get_iocstate(ioc, 1); ··· 2016 1897 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", 2017 1898 ioc->name, __func__); 2018 1899 rc = -EAGAIN; 2019 - goto out; 1900 + goto unmap; 2020 1901 } 2021 1902 2022 1903 rc = 0; ··· 2038 1919 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | 2039 1920 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); 2040 1921 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; 2041 - dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio), 2042 - blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL); 2043 - if (!dma_addr_out) { 2044 - mpt2sas_base_free_smid(ioc, smid); 2045 - goto unmap; 1922 + if (req->bio->bi_vcnt > 1) { 1923 + ioc->base_add_sg_single(psge, sgl_flags | 1924 + (blk_rq_bytes(req) - 4), pci_dma_out); 1925 + } else { 1926 + ioc->base_add_sg_single(psge, sgl_flags | 1927 + (blk_rq_bytes(req) - 4), dma_addr_out); 2046 1928 } 2047 - 2048 - ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(req) - 4), 2049 - dma_addr_out); 2050 1929 2051 1930 /* incr sgel */ 2052 1931 psge += ioc->sge_size; ··· 2054 1937 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | 2055 1938 MPI2_SGE_FLAGS_END_OF_LIST); 2056 1939 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; 2057 - dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio), 2058 - blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL); 2059 - if (!dma_addr_in) { 2060 - mpt2sas_base_free_smid(ioc, smid); 2061 - goto unmap; 1940 + if (rsp->bio->bi_vcnt > 1) { 1941 + ioc->base_add_sg_single(psge, sgl_flags | 1942 + (blk_rq_bytes(rsp) + 4), pci_dma_in); 1943 + } else { 1944 + ioc->base_add_sg_single(psge, sgl_flags | 1945 + (blk_rq_bytes(rsp) + 4), dma_addr_in); 2062 1946 } 2063 - 2064 - ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(rsp) + 4), 2065 - dma_addr_in); 2066 1947 2067 1948 dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "%s - " 2068 1949 "sending smp request\n", ioc->name, __func__)); ··· 2097 1982 req->resid_len = 0; 2098 1983 rsp->resid_len -= 2099 1984 le16_to_cpu(mpi_reply->ResponseDataLength); 1985 + /* check if the resp needs to be copied from the allocated 1986 + * pci mem */ 1987 + if (rsp->bio->bi_vcnt > 1) { 1988 + u32 offset = 0; 1989 + u32 bytes_to_copy = 1990 + le16_to_cpu(mpi_reply->ResponseDataLength); 1991 + bio_for_each_segment(bvec, rsp->bio, i) { 1992 + if (bytes_to_copy <= bvec->bv_len) { 1993 + memcpy(page_address(bvec->bv_page) + 1994 + bvec->bv_offset, pci_addr_in + 1995 + offset, bytes_to_copy); 1996 + break; 1997 + } else { 1998 + memcpy(page_address(bvec->bv_page) + 1999 + bvec->bv_offset, pci_addr_in + 2000 + offset, bvec->bv_len); 2001 + bytes_to_copy -= bvec->bv_len; 2002 + } 2003 + offset += bvec->bv_len; 2004 + } 2005 + } 2100 2006 } else { 2101 2007 dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT 2102 2008 "%s - no reply\n", ioc->name, __func__)); ··· 2138 2002 if (dma_addr_in) 2139 2003 pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp), 2140 2004 PCI_DMA_BIDIRECTIONAL); 2005 + 2006 + free_pci: 2007 + if (pci_addr_out) 2008 + pci_free_consistent(ioc->pdev, blk_rq_bytes(req), pci_addr_out, 2009 + pci_dma_out); 2010 + 2011 + if (pci_addr_in) 2012 + pci_free_consistent(ioc->pdev, blk_rq_bytes(rsp), pci_addr_in, 2013 + pci_dma_in); 2141 2014 2142 2015 out: 2143 2016 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
+2 -1
drivers/scsi/pm8001/pm8001_defs.h
··· 66 66 67 67 /* driver compile-time configuration */ 68 68 #define PM8001_MAX_CCB 512 /* max ccbs supported */ 69 + #define PM8001_MPI_QUEUE 1024 /* maximum mpi queue entries */ 69 70 #define PM8001_MAX_INB_NUM 1 70 71 #define PM8001_MAX_OUTB_NUM 1 71 - #define PM8001_CAN_QUEUE 128 /* SCSI Queue depth */ 72 + #define PM8001_CAN_QUEUE 508 /* SCSI Queue depth */ 72 73 73 74 /* unchangeable hardware details */ 74 75 #define PM8001_MAX_PHYS 8 /* max. possible phys */
+13 -10
drivers/scsi/pm8001/pm8001_hwi.c
··· 192 192 pm8001_ha->main_cfg_tbl.fatal_err_interrupt = 0x01; 193 193 for (i = 0; i < qn; i++) { 194 194 pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt = 195 - 0x00000100 | (0x00000040 << 16) | (0x00<<30); 195 + PM8001_MPI_QUEUE | (64 << 16) | (0x00<<30); 196 196 pm8001_ha->inbnd_q_tbl[i].upper_base_addr = 197 197 pm8001_ha->memoryMap.region[IB].phys_addr_hi; 198 198 pm8001_ha->inbnd_q_tbl[i].lower_base_addr = ··· 218 218 } 219 219 for (i = 0; i < qn; i++) { 220 220 pm8001_ha->outbnd_q_tbl[i].element_size_cnt = 221 - 256 | (64 << 16) | (1<<30); 221 + PM8001_MPI_QUEUE | (64 << 16) | (0x01<<30); 222 222 pm8001_ha->outbnd_q_tbl[i].upper_base_addr = 223 223 pm8001_ha->memoryMap.region[OB].phys_addr_hi; 224 224 pm8001_ha->outbnd_q_tbl[i].lower_base_addr = ··· 1245 1245 /* Stores the new consumer index */ 1246 1246 consumer_index = pm8001_read_32(circularQ->ci_virt); 1247 1247 circularQ->consumer_index = cpu_to_le32(consumer_index); 1248 - if (((circularQ->producer_idx + bcCount) % 256) == 1248 + if (((circularQ->producer_idx + bcCount) % PM8001_MPI_QUEUE) == 1249 1249 le32_to_cpu(circularQ->consumer_index)) { 1250 1250 *messagePtr = NULL; 1251 1251 return -1; ··· 1253 1253 /* get memory IOMB buffer address */ 1254 1254 offset = circularQ->producer_idx * 64; 1255 1255 /* increment to next bcCount element */ 1256 - circularQ->producer_idx = (circularQ->producer_idx + bcCount) % 256; 1256 + circularQ->producer_idx = (circularQ->producer_idx + bcCount) 1257 + % PM8001_MPI_QUEUE; 1257 1258 /* Adds that distance to the base of the region virtual address plus 1258 1259 the message header size*/ 1259 1260 msgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + offset); ··· 1327 1326 return 0; 1328 1327 } 1329 1328 /* free the circular queue buffer elements associated with the message*/ 1330 - circularQ->consumer_idx = (circularQ->consumer_idx + bc) % 256; 1329 + circularQ->consumer_idx = (circularQ->consumer_idx + bc) 1330 + % PM8001_MPI_QUEUE; 1331 1331 /* update the CI of outbound queue */ 1332 1332 pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset, 1333 1333 circularQ->consumer_idx); ··· 1385 1383 circularQ->consumer_idx = 1386 1384 (circularQ->consumer_idx + 1387 1385 ((le32_to_cpu(msgHeader_tmp) 1388 - >> 24) & 0x1f)) % 256; 1386 + >> 24) & 0x1f)) 1387 + % PM8001_MPI_QUEUE; 1389 1388 msgHeader_tmp = 0; 1390 1389 pm8001_write_32(msgHeader, 0, 0); 1391 1390 /* update the CI of outbound queue */ ··· 1399 1396 circularQ->consumer_idx = 1400 1397 (circularQ->consumer_idx + 1401 1398 ((le32_to_cpu(msgHeader_tmp) >> 24) & 1402 - 0x1f)) % 256; 1399 + 0x1f)) % PM8001_MPI_QUEUE; 1403 1400 msgHeader_tmp = 0; 1404 1401 pm8001_write_32(msgHeader, 0, 0); 1405 1402 /* update the CI of outbound queue */ ··· 3360 3357 struct fw_control_ex fw_control_context; 3361 3358 struct fw_flash_Update_resp *ppayload = 3362 3359 (struct fw_flash_Update_resp *)(piomb + 4); 3363 - u32 tag = ppayload->tag; 3360 + u32 tag = le32_to_cpu(ppayload->tag); 3364 3361 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; 3365 3362 status = le32_to_cpu(ppayload->status); 3366 3363 memcpy(&fw_control_context, ··· 3706 3703 */ 3707 3704 static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb) 3708 3705 { 3709 - u32 pHeader = (u32)*(u32 *)piomb; 3710 - u8 opc = (u8)(pHeader & 0xFFF); 3706 + __le32 pHeader = *(__le32 *)piomb; 3707 + u8 opc = (u8)((le32_to_cpu(pHeader)) & 0xFFF); 3711 3708 3712 3709 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("process_one_iomb:")); 3713 3710
+1 -1
drivers/scsi/pm8001/pm8001_hwi.h
··· 599 599 * 600 600 */ 601 601 struct fw_flash_Update_resp { 602 - dma_addr_t tag; 602 + __le32 tag; 603 603 __le32 status; 604 604 u32 reserved[13]; 605 605 } __attribute__((packed, aligned(4)));
+5 -5
drivers/scsi/pm8001/pm8001_init.c
··· 235 235 pm8001_ha->memoryMap.region[PI].alignment = 4; 236 236 237 237 /* MPI Memory region 5 inbound queues */ 238 - pm8001_ha->memoryMap.region[IB].num_elements = 256; 238 + pm8001_ha->memoryMap.region[IB].num_elements = PM8001_MPI_QUEUE; 239 239 pm8001_ha->memoryMap.region[IB].element_size = 64; 240 - pm8001_ha->memoryMap.region[IB].total_len = 256 * 64; 240 + pm8001_ha->memoryMap.region[IB].total_len = PM8001_MPI_QUEUE * 64; 241 241 pm8001_ha->memoryMap.region[IB].alignment = 64; 242 242 243 - /* MPI Memory region 6 inbound queues */ 244 - pm8001_ha->memoryMap.region[OB].num_elements = 256; 243 + /* MPI Memory region 6 outbound queues */ 244 + pm8001_ha->memoryMap.region[OB].num_elements = PM8001_MPI_QUEUE; 245 245 pm8001_ha->memoryMap.region[OB].element_size = 64; 246 - pm8001_ha->memoryMap.region[OB].total_len = 256 * 64; 246 + pm8001_ha->memoryMap.region[OB].total_len = PM8001_MPI_QUEUE * 64; 247 247 pm8001_ha->memoryMap.region[OB].alignment = 64; 248 248 249 249 /* Memory region write DMA*/
+6
drivers/scsi/scsi.c
··· 90 90 EXPORT_SYMBOL(scsi_logging_level); 91 91 #endif 92 92 93 + #if IS_ENABLED(CONFIG_PM) || IS_ENABLED(CONFIG_BLK_DEV_SD) 94 + /* sd and scsi_pm need to coordinate flushing async actions */ 95 + LIST_HEAD(scsi_sd_probe_domain); 96 + EXPORT_SYMBOL(scsi_sd_probe_domain); 97 + #endif 98 + 93 99 /* NB: These are exposed through /proc/scsi/scsi and form part of the ABI. 94 100 * You may not alter any existing entry (although adding new ones is 95 101 * encouraged once assigned by ANSI/INCITS T10
+7 -3
drivers/scsi/scsi_lib.c
··· 2348 2348 * 2349 2349 * Must be called with user context, may sleep. 2350 2350 */ 2351 - void 2352 - scsi_device_resume(struct scsi_device *sdev) 2351 + void scsi_device_resume(struct scsi_device *sdev) 2353 2352 { 2354 - if(scsi_device_set_state(sdev, SDEV_RUNNING)) 2353 + /* check if the device state was mutated prior to resume, and if 2354 + * so assume the state is being managed elsewhere (for example 2355 + * device deleted during suspend) 2356 + */ 2357 + if (sdev->sdev_state != SDEV_QUIESCE || 2358 + scsi_device_set_state(sdev, SDEV_RUNNING)) 2355 2359 return; 2356 2360 scsi_run_queue(sdev->request_queue); 2357 2361 }
+1 -1
drivers/scsi/scsi_pm.c
··· 97 97 { 98 98 if (scsi_is_sdev_device(dev)) { 99 99 /* sd probing uses async_schedule. Wait until it finishes. */ 100 - async_synchronize_full(); 100 + async_synchronize_full_domain(&scsi_sd_probe_domain); 101 101 102 102 } else if (scsi_is_host_device(dev)) { 103 103 /* Wait until async scanning is finished */
+2
drivers/scsi/scsi_priv.h
··· 163 163 static inline void scsi_autopm_put_host(struct Scsi_Host *h) {} 164 164 #endif /* CONFIG_PM_RUNTIME */ 165 165 166 + extern struct list_head scsi_sd_probe_domain; 167 + 166 168 /* 167 169 * internal scsi timeout functions: for use by mid-layer and transport 168 170 * classes.
+14 -10
drivers/scsi/scsi_transport_fc.c
··· 2808 2808 FC_RPORT_DEVLOSS_PENDING | 2809 2809 FC_RPORT_DEVLOSS_CALLBK_DONE); 2810 2810 2811 + spin_unlock_irqrestore(shost->host_lock, flags); 2812 + 2811 2813 /* if target, initiate a scan */ 2812 2814 if (rport->scsi_target_id != -1) { 2815 + scsi_target_unblock(&rport->dev); 2816 + 2817 + spin_lock_irqsave(shost->host_lock, 2818 + flags); 2813 2819 rport->flags |= FC_RPORT_SCAN_PENDING; 2814 2820 scsi_queue_work(shost, 2815 2821 &rport->scan_work); 2816 2822 spin_unlock_irqrestore(shost->host_lock, 2817 2823 flags); 2818 - scsi_target_unblock(&rport->dev); 2819 - } else 2820 - spin_unlock_irqrestore(shost->host_lock, 2821 - flags); 2824 + } 2822 2825 2823 2826 fc_bsg_goose_queue(rport); 2824 2827 ··· 2879 2876 if (fci->f->dd_fcrport_size) 2880 2877 memset(rport->dd_data, 0, 2881 2878 fci->f->dd_fcrport_size); 2879 + spin_unlock_irqrestore(shost->host_lock, flags); 2882 2880 2883 - if (rport->roles & FC_PORT_ROLE_FCP_TARGET) { 2881 + if (ids->roles & FC_PORT_ROLE_FCP_TARGET) { 2882 + scsi_target_unblock(&rport->dev); 2883 + 2884 2884 /* initiate a scan of the target */ 2885 + spin_lock_irqsave(shost->host_lock, flags); 2885 2886 rport->flags |= FC_RPORT_SCAN_PENDING; 2886 2887 scsi_queue_work(shost, &rport->scan_work); 2887 2888 spin_unlock_irqrestore(shost->host_lock, flags); 2888 - scsi_target_unblock(&rport->dev); 2889 - } else 2890 - spin_unlock_irqrestore(shost->host_lock, flags); 2891 - 2889 + } 2892 2890 return rport; 2893 2891 } 2894 2892 } ··· 3087 3083 /* ensure any stgt delete functions are done */ 3088 3084 fc_flush_work(shost); 3089 3085 3086 + scsi_target_unblock(&rport->dev); 3090 3087 /* initiate a scan of the target */ 3091 3088 spin_lock_irqsave(shost->host_lock, flags); 3092 3089 rport->flags |= FC_RPORT_SCAN_PENDING; 3093 3090 scsi_queue_work(shost, &rport->scan_work); 3094 3091 spin_unlock_irqrestore(shost->host_lock, flags); 3095 - scsi_target_unblock(&rport->dev); 3096 3092 } 3097 3093 } 3098 3094 EXPORT_SYMBOL(fc_remote_port_rolechg);
+2 -2
drivers/scsi/scsi_transport_spi.c
··· 1010 1010 u8 *buffer; 1011 1011 const int len = SPI_MAX_ECHO_BUFFER_SIZE*2; 1012 1012 1013 - if (unlikely(scsi_device_get(sdev))) 1013 + if (unlikely(spi_dv_in_progress(starget))) 1014 1014 return; 1015 1015 1016 - if (unlikely(spi_dv_in_progress(starget))) 1016 + if (unlikely(scsi_device_get(sdev))) 1017 1017 return; 1018 1018 spi_dv_in_progress(starget) = 1; 1019 1019
+3 -2
drivers/scsi/sd.c
··· 65 65 #include <scsi/scsicam.h> 66 66 67 67 #include "sd.h" 68 + #include "scsi_priv.h" 68 69 #include "scsi_logging.h" 69 70 70 71 MODULE_AUTHOR("Eric Youngdale"); ··· 2723 2722 dev_set_drvdata(dev, sdkp); 2724 2723 2725 2724 get_device(&sdkp->dev); /* prevent release before async_schedule */ 2726 - async_schedule(sd_probe_async, sdkp); 2725 + async_schedule_domain(sd_probe_async, sdkp, &scsi_sd_probe_domain); 2727 2726 2728 2727 return 0; 2729 2728 ··· 2757 2756 sdkp = dev_get_drvdata(dev); 2758 2757 scsi_autopm_get_device(sdkp->device); 2759 2758 2760 - async_synchronize_full(); 2759 + async_synchronize_full_domain(&scsi_sd_probe_domain); 2761 2760 blk_queue_prep_rq(sdkp->device->request_queue, scsi_prep_fn); 2762 2761 blk_queue_unprep_rq(sdkp->device->request_queue, NULL); 2763 2762 device_del(&sdkp->dev);
+99 -84
drivers/scsi/sg.c
··· 104 104 static int sg_add(struct device *, struct class_interface *); 105 105 static void sg_remove(struct device *, struct class_interface *); 106 106 107 - static DEFINE_MUTEX(sg_mutex); 107 + static DEFINE_SPINLOCK(sg_open_exclusive_lock); 108 108 109 109 static DEFINE_IDR(sg_index_idr); 110 110 static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock ··· 137 137 char res_used; /* 1 -> using reserve buffer, 0 -> not ... */ 138 138 char orphan; /* 1 -> drop on sight, 0 -> normal */ 139 139 char sg_io_owned; /* 1 -> packet belongs to SG_IO */ 140 - volatile char done; /* 0->before bh, 1->before read, 2->read */ 140 + /* done protected by rq_list_lock */ 141 + char done; /* 0->before bh, 1->before read, 2->read */ 141 142 struct request *rq; 142 143 struct bio *bio; 143 144 struct execute_work ew; 144 145 } Sg_request; 145 146 146 147 typedef struct sg_fd { /* holds the state of a file descriptor */ 148 + /* sfd_siblings is protected by sg_index_lock */ 147 149 struct list_head sfd_siblings; 148 150 struct sg_device *parentdp; /* owning device */ 149 151 wait_queue_head_t read_wait; /* queue read until command done */ ··· 159 157 Sg_request req_arr[SG_MAX_QUEUE]; /* used as singly-linked list */ 160 158 char low_dma; /* as in parent but possibly overridden to 1 */ 161 159 char force_packid; /* 1 -> pack_id input to read(), 0 -> ignored */ 162 - volatile char closed; /* 1 -> fd closed but request(s) outstanding */ 163 160 char cmd_q; /* 1 -> allow command queuing, 0 -> don't */ 164 161 char next_cmd_len; /* 0 -> automatic (def), >0 -> use on next write() */ 165 162 char keep_orphan; /* 0 -> drop orphan (def), 1 -> keep for read() */ ··· 172 171 wait_queue_head_t o_excl_wait; /* queue open() when O_EXCL in use */ 173 172 int sg_tablesize; /* adapter's max scatter-gather table size */ 174 173 u32 index; /* device index number */ 174 + /* sfds is protected by sg_index_lock */ 175 175 struct list_head sfds; 176 176 volatile char detached; /* 0->attached, 1->detached pending removal */ 177 - volatile char exclude; /* opened for exclusive access */ 177 + /* exclude protected by sg_open_exclusive_lock */ 178 + char exclude; /* opened for exclusive access */ 178 179 char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */ 179 180 struct gendisk *disk; 180 181 struct cdev * cdev; /* char_dev [sysfs: /sys/cdev/major/sg<n>] */ ··· 224 221 return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE); 225 222 } 226 223 224 + static int get_exclude(Sg_device *sdp) 225 + { 226 + unsigned long flags; 227 + int ret; 228 + 229 + spin_lock_irqsave(&sg_open_exclusive_lock, flags); 230 + ret = sdp->exclude; 231 + spin_unlock_irqrestore(&sg_open_exclusive_lock, flags); 232 + return ret; 233 + } 234 + 235 + static int set_exclude(Sg_device *sdp, char val) 236 + { 237 + unsigned long flags; 238 + 239 + spin_lock_irqsave(&sg_open_exclusive_lock, flags); 240 + sdp->exclude = val; 241 + spin_unlock_irqrestore(&sg_open_exclusive_lock, flags); 242 + return val; 243 + } 244 + 245 + static int sfds_list_empty(Sg_device *sdp) 246 + { 247 + unsigned long flags; 248 + int ret; 249 + 250 + read_lock_irqsave(&sg_index_lock, flags); 251 + ret = list_empty(&sdp->sfds); 252 + read_unlock_irqrestore(&sg_index_lock, flags); 253 + return ret; 254 + } 255 + 227 256 static int 228 257 sg_open(struct inode *inode, struct file *filp) 229 258 { ··· 267 232 int res; 268 233 int retval; 269 234 270 - mutex_lock(&sg_mutex); 271 235 nonseekable_open(inode, filp); 272 236 SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev, flags)); 273 237 sdp = sg_get_dev(dev); ··· 298 264 retval = -EPERM; /* Can't lock it with read only access */ 299 265 goto error_out; 300 266 } 301 - if (!list_empty(&sdp->sfds) && (flags & O_NONBLOCK)) { 267 + if (!sfds_list_empty(sdp) && (flags & O_NONBLOCK)) { 302 268 retval = -EBUSY; 303 269 goto error_out; 304 270 } 305 - res = 0; 306 - __wait_event_interruptible(sdp->o_excl_wait, 307 - ((!list_empty(&sdp->sfds) || sdp->exclude) ? 0 : (sdp->exclude = 1)), res); 271 + res = wait_event_interruptible(sdp->o_excl_wait, 272 + ((!sfds_list_empty(sdp) || get_exclude(sdp)) ? 0 : set_exclude(sdp, 1))); 308 273 if (res) { 309 274 retval = res; /* -ERESTARTSYS because signal hit process */ 310 275 goto error_out; 311 276 } 312 - } else if (sdp->exclude) { /* some other fd has an exclusive lock on dev */ 277 + } else if (get_exclude(sdp)) { /* some other fd has an exclusive lock on dev */ 313 278 if (flags & O_NONBLOCK) { 314 279 retval = -EBUSY; 315 280 goto error_out; 316 281 } 317 - res = 0; 318 - __wait_event_interruptible(sdp->o_excl_wait, (!sdp->exclude), 319 - res); 282 + res = wait_event_interruptible(sdp->o_excl_wait, !get_exclude(sdp)); 320 283 if (res) { 321 284 retval = res; /* -ERESTARTSYS because signal hit process */ 322 285 goto error_out; ··· 323 292 retval = -ENODEV; 324 293 goto error_out; 325 294 } 326 - if (list_empty(&sdp->sfds)) { /* no existing opens on this device */ 295 + if (sfds_list_empty(sdp)) { /* no existing opens on this device */ 327 296 sdp->sgdebug = 0; 328 297 q = sdp->device->request_queue; 329 298 sdp->sg_tablesize = queue_max_segments(q); ··· 332 301 filp->private_data = sfp; 333 302 else { 334 303 if (flags & O_EXCL) { 335 - sdp->exclude = 0; /* undo if error */ 304 + set_exclude(sdp, 0); /* undo if error */ 336 305 wake_up_interruptible(&sdp->o_excl_wait); 337 306 } 338 307 retval = -ENOMEM; ··· 348 317 sg_put: 349 318 if (sdp) 350 319 sg_put_dev(sdp); 351 - mutex_unlock(&sg_mutex); 352 320 return retval; 353 321 } 354 322 ··· 362 332 return -ENXIO; 363 333 SCSI_LOG_TIMEOUT(3, printk("sg_release: %s\n", sdp->disk->disk_name)); 364 334 365 - sfp->closed = 1; 366 - 367 - sdp->exclude = 0; 335 + set_exclude(sdp, 0); 368 336 wake_up_interruptible(&sdp->o_excl_wait); 369 337 370 338 scsi_autopm_put_device(sdp->device); ··· 426 398 retval = -EAGAIN; 427 399 goto free_old_hdr; 428 400 } 429 - while (1) { 430 - retval = 0; /* following macro beats race condition */ 431 - __wait_event_interruptible(sfp->read_wait, 432 - (sdp->detached || 433 - (srp = sg_get_rq_mark(sfp, req_pack_id))), 434 - retval); 435 - if (sdp->detached) { 436 - retval = -ENODEV; 437 - goto free_old_hdr; 438 - } 439 - if (0 == retval) 440 - break; 441 - 401 + retval = wait_event_interruptible(sfp->read_wait, 402 + (sdp->detached || 403 + (srp = sg_get_rq_mark(sfp, req_pack_id)))); 404 + if (sdp->detached) { 405 + retval = -ENODEV; 406 + goto free_old_hdr; 407 + } 408 + if (retval) { 442 409 /* -ERESTARTSYS as signal hit process */ 443 410 goto free_old_hdr; 444 411 } ··· 794 771 return 0; 795 772 } 796 773 797 - static int 774 + static int srp_done(Sg_fd *sfp, Sg_request *srp) 775 + { 776 + unsigned long flags; 777 + int ret; 778 + 779 + read_lock_irqsave(&sfp->rq_list_lock, flags); 780 + ret = srp->done; 781 + read_unlock_irqrestore(&sfp->rq_list_lock, flags); 782 + return ret; 783 + } 784 + 785 + static long 798 786 sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) 799 787 { 800 788 void __user *p = (void __user *)arg; ··· 825 791 826 792 switch (cmd_in) { 827 793 case SG_IO: 828 - { 829 - int blocking = 1; /* ignore O_NONBLOCK flag */ 830 - 831 - if (sdp->detached) 832 - return -ENODEV; 833 - if (!scsi_block_when_processing_errors(sdp->device)) 834 - return -ENXIO; 835 - if (!access_ok(VERIFY_WRITE, p, SZ_SG_IO_HDR)) 836 - return -EFAULT; 837 - result = 838 - sg_new_write(sfp, filp, p, SZ_SG_IO_HDR, 839 - blocking, read_only, 1, &srp); 840 - if (result < 0) 841 - return result; 842 - while (1) { 843 - result = 0; /* following macro to beat race condition */ 844 - __wait_event_interruptible(sfp->read_wait, 845 - (srp->done || sdp->detached), 846 - result); 847 - if (sdp->detached) 848 - return -ENODEV; 849 - write_lock_irq(&sfp->rq_list_lock); 850 - if (srp->done) { 851 - srp->done = 2; 852 - write_unlock_irq(&sfp->rq_list_lock); 853 - break; 854 - } 855 - srp->orphan = 1; 856 - write_unlock_irq(&sfp->rq_list_lock); 857 - return result; /* -ERESTARTSYS because signal hit process */ 858 - } 794 + if (sdp->detached) 795 + return -ENODEV; 796 + if (!scsi_block_when_processing_errors(sdp->device)) 797 + return -ENXIO; 798 + if (!access_ok(VERIFY_WRITE, p, SZ_SG_IO_HDR)) 799 + return -EFAULT; 800 + result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR, 801 + 1, read_only, 1, &srp); 802 + if (result < 0) 803 + return result; 804 + result = wait_event_interruptible(sfp->read_wait, 805 + (srp_done(sfp, srp) || sdp->detached)); 806 + if (sdp->detached) 807 + return -ENODEV; 808 + write_lock_irq(&sfp->rq_list_lock); 809 + if (srp->done) { 810 + srp->done = 2; 811 + write_unlock_irq(&sfp->rq_list_lock); 859 812 result = sg_new_read(sfp, p, SZ_SG_IO_HDR, srp); 860 813 return (result < 0) ? result : 0; 861 814 } 815 + srp->orphan = 1; 816 + write_unlock_irq(&sfp->rq_list_lock); 817 + return result; /* -ERESTARTSYS because signal hit process */ 862 818 case SG_SET_TIMEOUT: 863 819 result = get_user(val, ip); 864 820 if (result) ··· 1115 1091 } 1116 1092 } 1117 1093 1118 - static long 1119 - sg_unlocked_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) 1120 - { 1121 - int ret; 1122 - 1123 - mutex_lock(&sg_mutex); 1124 - ret = sg_ioctl(filp, cmd_in, arg); 1125 - mutex_unlock(&sg_mutex); 1126 - 1127 - return ret; 1128 - } 1129 - 1130 1094 #ifdef CONFIG_COMPAT 1131 1095 static long sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) 1132 1096 { ··· 1148 1136 int count = 0; 1149 1137 unsigned long iflags; 1150 1138 1151 - if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)) 1152 - || sfp->closed) 1139 + sfp = filp->private_data; 1140 + if (!sfp) 1141 + return POLLERR; 1142 + sdp = sfp->parentdp; 1143 + if (!sdp) 1153 1144 return POLLERR; 1154 1145 poll_wait(filp, &sfp->read_wait, wait); 1155 1146 read_lock_irqsave(&sfp->rq_list_lock, iflags); ··· 1362 1347 .read = sg_read, 1363 1348 .write = sg_write, 1364 1349 .poll = sg_poll, 1365 - .unlocked_ioctl = sg_unlocked_ioctl, 1350 + .unlocked_ioctl = sg_ioctl, 1366 1351 #ifdef CONFIG_COMPAT 1367 1352 .compat_ioctl = sg_compat_ioctl, 1368 1353 #endif ··· 2327 2312 const struct file_operations * fops; 2328 2313 }; 2329 2314 2330 - static struct sg_proc_leaf sg_proc_leaf_arr[] = { 2315 + static const struct sg_proc_leaf sg_proc_leaf_arr[] = { 2331 2316 {"allow_dio", &adio_fops}, 2332 2317 {"debug", &debug_fops}, 2333 2318 {"def_reserved_size", &dressz_fops}, ··· 2347 2332 if (!sg_proc_sgp) 2348 2333 return 1; 2349 2334 for (k = 0; k < num_leaves; ++k) { 2350 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k]; 2335 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k]; 2351 2336 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO; 2352 2337 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops); 2353 2338 } ··· 2548 2533 fp->reserve.bufflen, 2549 2534 (int) fp->reserve.k_use_sg, 2550 2535 (int) fp->low_dma); 2551 - seq_printf(s, " cmd_q=%d f_packid=%d k_orphan=%d closed=%d\n", 2536 + seq_printf(s, " cmd_q=%d f_packid=%d k_orphan=%d closed=0\n", 2552 2537 (int) fp->cmd_q, (int) fp->force_packid, 2553 - (int) fp->keep_orphan, (int) fp->closed); 2538 + (int) fp->keep_orphan); 2554 2539 for (m = 0, srp = fp->headrp; 2555 2540 srp != NULL; 2556 2541 ++m, srp = srp->nextrp) { ··· 2627 2612 scsidp->lun, 2628 2613 scsidp->host->hostt->emulated); 2629 2614 seq_printf(s, " sg_tablesize=%d excl=%d\n", 2630 - sdp->sg_tablesize, sdp->exclude); 2615 + sdp->sg_tablesize, get_exclude(sdp)); 2631 2616 sg_proc_debug_helper(s, sdp); 2632 2617 } 2633 2618 read_unlock_irqrestore(&sg_index_lock, iflags);
+1 -1
drivers/scsi/st.h
··· 35 35 /* The tape buffer descriptor. */ 36 36 struct st_buffer { 37 37 unsigned char dma; /* DMA-able buffer */ 38 - unsigned char do_dio; /* direct i/o set up? */ 39 38 unsigned char cleared; /* internal buffer cleared after open? */ 39 + unsigned short do_dio; /* direct i/o set up? */ 40 40 int buffer_size; 41 41 int buffer_blocks; 42 42 int buffer_bytes;
+15 -5
drivers/scsi/storvsc_drv.c
··· 785 785 /* 786 786 * If there is an error; offline the device since all 787 787 * error recovery strategies would have already been 788 - * deployed on the host side. 788 + * deployed on the host side. However, if the command 789 + * were a pass-through command deal with it appropriately. 789 790 */ 790 - if (vm_srb->srb_status == SRB_STATUS_ERROR) 791 - scmnd->result = DID_TARGET_FAILURE << 16; 792 - else 793 - scmnd->result = vm_srb->scsi_status; 791 + scmnd->result = vm_srb->scsi_status; 792 + 793 + if (vm_srb->srb_status == SRB_STATUS_ERROR) { 794 + switch (scmnd->cmnd[0]) { 795 + case ATA_16: 796 + case ATA_12: 797 + set_host_byte(scmnd, DID_PASSTHROUGH); 798 + break; 799 + default: 800 + set_host_byte(scmnd, DID_TARGET_FAILURE); 801 + } 802 + } 803 + 794 804 795 805 /* 796 806 * If the LUN is invalid; remove the device.
+4 -4
drivers/scsi/ufs/ufshcd.c
··· 1032 1032 return -EIO; 1033 1033 1034 1034 /* Configure UTRL and UTMRL base address registers */ 1035 - writel(hba->utrdl_dma_addr, 1036 - (hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_BASE_L)); 1037 1035 writel(lower_32_bits(hba->utrdl_dma_addr), 1036 + (hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_BASE_L)); 1037 + writel(upper_32_bits(hba->utrdl_dma_addr), 1038 1038 (hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_BASE_H)); 1039 - writel(hba->utmrdl_dma_addr, 1039 + writel(lower_32_bits(hba->utmrdl_dma_addr), 1040 1040 (hba->mmio_base + REG_UTP_TASK_REQ_LIST_BASE_L)); 1041 1041 writel(upper_32_bits(hba->utmrdl_dma_addr), 1042 1042 (hba->mmio_base + REG_UTP_TASK_REQ_LIST_BASE_H)); ··· 1160 1160 task_result = be32_to_cpu(task_rsp_upiup->header.dword_1); 1161 1161 task_result = ((task_result & MASK_TASK_RESPONSE) >> 8); 1162 1162 1163 - if (task_result != UPIU_TASK_MANAGEMENT_FUNC_COMPL || 1163 + if (task_result != UPIU_TASK_MANAGEMENT_FUNC_COMPL && 1164 1164 task_result != UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED) 1165 1165 task_result = FAILED; 1166 1166 } else {
+2
include/scsi/iscsi_proto.h
··· 661 661 662 662 #define ISCSI_DEF_TIME2WAIT 2 663 663 664 + #define ISCSI_NAME_LEN 224 665 + 664 666 /************************* RFC 3720 End *****************************/ 665 667 666 668 #endif /* ISCSI_PROTO_H */
+1
include/scsi/sas.h
··· 103 103 }; 104 104 105 105 enum sas_protocol { 106 + SAS_PROTOCOL_NONE = 0, 106 107 SAS_PROTOCOL_SATA = 0x01, 107 108 SAS_PROTOCOL_SMP = 0x02, 108 109 SAS_PROTOCOL_STP = 0x04,