be_cmds.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. /**
  2. * Copyright (C) 2005 - 2013 Emulex
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Contact Information:
  11. * linux-drivers@emulex.com
  12. *
  13. * Emulex
  14. * 3333 Susan Street
  15. * Costa Mesa, CA 92626
  16. */
  17. #include <scsi/iscsi_proto.h>
  18. #include "be_main.h"
  19. #include "be.h"
  20. #include "be_mgmt.h"
  21. int beiscsi_pci_soft_reset(struct beiscsi_hba *phba)
  22. {
  23. u32 sreset;
  24. u8 *pci_reset_offset = 0;
  25. u8 *pci_online0_offset = 0;
  26. u8 *pci_online1_offset = 0;
  27. u32 pconline0 = 0;
  28. u32 pconline1 = 0;
  29. u32 i;
  30. pci_reset_offset = (u8 *)phba->pci_va + BE2_SOFT_RESET;
  31. pci_online0_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE0;
  32. pci_online1_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE1;
  33. sreset = readl((void *)pci_reset_offset);
  34. sreset |= BE2_SET_RESET;
  35. writel(sreset, (void *)pci_reset_offset);
  36. i = 0;
  37. while (sreset & BE2_SET_RESET) {
  38. if (i > 64)
  39. break;
  40. msleep(100);
  41. sreset = readl((void *)pci_reset_offset);
  42. i++;
  43. }
  44. if (sreset & BE2_SET_RESET) {
  45. printk(KERN_ERR DRV_NAME
  46. " Soft Reset did not deassert\n");
  47. return -EIO;
  48. }
  49. pconline1 = BE2_MPU_IRAM_ONLINE;
  50. writel(pconline0, (void *)pci_online0_offset);
  51. writel(pconline1, (void *)pci_online1_offset);
  52. sreset |= BE2_SET_RESET;
  53. writel(sreset, (void *)pci_reset_offset);
  54. i = 0;
  55. while (sreset & BE2_SET_RESET) {
  56. if (i > 64)
  57. break;
  58. msleep(1);
  59. sreset = readl((void *)pci_reset_offset);
  60. i++;
  61. }
  62. if (sreset & BE2_SET_RESET) {
  63. printk(KERN_ERR DRV_NAME
  64. " MPU Online Soft Reset did not deassert\n");
  65. return -EIO;
  66. }
  67. return 0;
  68. }
  69. int be_chk_reset_complete(struct beiscsi_hba *phba)
  70. {
  71. unsigned int num_loop;
  72. u8 *mpu_sem = 0;
  73. u32 status;
  74. num_loop = 1000;
  75. mpu_sem = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
  76. msleep(5000);
  77. while (num_loop) {
  78. status = readl((void *)mpu_sem);
  79. if ((status & 0x80000000) || (status & 0x0000FFFF) == 0xC000)
  80. break;
  81. msleep(60);
  82. num_loop--;
  83. }
  84. if ((status & 0x80000000) || (!num_loop)) {
  85. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  86. "BC_%d : Failed in be_chk_reset_complete"
  87. "status = 0x%x\n", status);
  88. return -EIO;
  89. }
  90. return 0;
  91. }
  92. void be_mcc_notify(struct beiscsi_hba *phba)
  93. {
  94. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  95. u32 val = 0;
  96. val |= mccq->id & DB_MCCQ_RING_ID_MASK;
  97. val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
  98. iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
  99. }
  100. unsigned int alloc_mcc_tag(struct beiscsi_hba *phba)
  101. {
  102. unsigned int tag = 0;
  103. if (phba->ctrl.mcc_tag_available) {
  104. tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
  105. phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
  106. phba->ctrl.mcc_numtag[tag] = 0;
  107. }
  108. if (tag) {
  109. phba->ctrl.mcc_tag_available--;
  110. if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
  111. phba->ctrl.mcc_alloc_index = 0;
  112. else
  113. phba->ctrl.mcc_alloc_index++;
  114. }
  115. return tag;
  116. }
  117. /*
  118. * beiscsi_mccq_compl()- Wait for completion of MBX
  119. * @phba: Driver private structure
  120. * @tag: Tag for the MBX Command
  121. * @wrb: the WRB used for the MBX Command
  122. * @cmd_hdr: IOCTL Hdr for the MBX Cmd
  123. *
  124. * Waits for MBX completion with the passed TAG.
  125. *
  126. * return
  127. * Success: 0
  128. * Failure: Non-Zero
  129. **/
  130. int beiscsi_mccq_compl(struct beiscsi_hba *phba,
  131. uint32_t tag, struct be_mcc_wrb **wrb,
  132. void *cmd_hdr)
  133. {
  134. int rc = 0;
  135. uint32_t mcc_tag_response;
  136. uint16_t status = 0, addl_status = 0, wrb_num = 0;
  137. struct be_mcc_wrb *temp_wrb;
  138. struct be_cmd_req_hdr *ioctl_hdr;
  139. struct be_cmd_resp_hdr *ioctl_resp_hdr;
  140. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  141. if (beiscsi_error(phba)) {
  142. free_mcc_tag(&phba->ctrl, tag);
  143. return -EIO;
  144. }
  145. /* wait for the mccq completion */
  146. rc = wait_event_interruptible_timeout(
  147. phba->ctrl.mcc_wait[tag],
  148. phba->ctrl.mcc_numtag[tag],
  149. msecs_to_jiffies(
  150. BEISCSI_HOST_MBX_TIMEOUT));
  151. if (rc <= 0) {
  152. beiscsi_log(phba, KERN_ERR,
  153. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  154. BEISCSI_LOG_CONFIG,
  155. "BC_%d : MBX Cmd Completion timed out\n");
  156. rc = -EBUSY;
  157. /* decrement the mccq used count */
  158. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  159. goto release_mcc_tag;
  160. } else
  161. rc = 0;
  162. mcc_tag_response = phba->ctrl.mcc_numtag[tag];
  163. status = (mcc_tag_response & CQE_STATUS_MASK);
  164. addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >>
  165. CQE_STATUS_ADDL_SHIFT);
  166. if (cmd_hdr) {
  167. ioctl_hdr = (struct be_cmd_req_hdr *)cmd_hdr;
  168. } else {
  169. wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >>
  170. CQE_STATUS_WRB_SHIFT;
  171. temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
  172. ioctl_hdr = embedded_payload(temp_wrb);
  173. if (wrb)
  174. *wrb = temp_wrb;
  175. }
  176. if (status || addl_status) {
  177. beiscsi_log(phba, KERN_ERR,
  178. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  179. BEISCSI_LOG_CONFIG,
  180. "BC_%d : MBX Cmd Failed for "
  181. "Subsys : %d Opcode : %d with "
  182. "Status : %d and Extd_Status : %d\n",
  183. ioctl_hdr->subsystem,
  184. ioctl_hdr->opcode,
  185. status, addl_status);
  186. if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  187. ioctl_resp_hdr = (struct be_cmd_resp_hdr *) ioctl_hdr;
  188. beiscsi_log(phba, KERN_WARNING,
  189. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  190. BEISCSI_LOG_CONFIG,
  191. "BC_%d : Insufficent Buffer Error "
  192. "Resp_Len : %d Actual_Resp_Len : %d\n",
  193. ioctl_resp_hdr->response_length,
  194. ioctl_resp_hdr->actual_resp_len);
  195. rc = -EAGAIN;
  196. goto release_mcc_tag;
  197. }
  198. rc = -EIO;
  199. }
  200. release_mcc_tag:
  201. /* Release the MCC entry */
  202. free_mcc_tag(&phba->ctrl, tag);
  203. return rc;
  204. }
  205. void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
  206. {
  207. spin_lock(&ctrl->mbox_lock);
  208. tag = tag & 0x000000FF;
  209. ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
  210. if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
  211. ctrl->mcc_free_index = 0;
  212. else
  213. ctrl->mcc_free_index++;
  214. ctrl->mcc_tag_available++;
  215. spin_unlock(&ctrl->mbox_lock);
  216. }
  217. bool is_link_state_evt(u32 trailer)
  218. {
  219. return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
  220. ASYNC_TRAILER_EVENT_CODE_MASK) ==
  221. ASYNC_EVENT_CODE_LINK_STATE);
  222. }
  223. static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
  224. {
  225. if (compl->flags != 0) {
  226. compl->flags = le32_to_cpu(compl->flags);
  227. WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
  228. return true;
  229. } else
  230. return false;
  231. }
  232. static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
  233. {
  234. compl->flags = 0;
  235. }
  236. /*
  237. * be_mcc_compl_process()- Check the MBX comapletion status
  238. * @ctrl: Function specific MBX data structure
  239. * @compl: Completion status of MBX Command
  240. *
  241. * Check for the MBX completion status when BMBX method used
  242. *
  243. * return
  244. * Success: Zero
  245. * Failure: Non-Zero
  246. **/
  247. static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
  248. struct be_mcc_compl *compl)
  249. {
  250. u16 compl_status, extd_status;
  251. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  252. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  253. struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
  254. struct be_cmd_resp_hdr *resp_hdr;
  255. be_dws_le_to_cpu(compl, 4);
  256. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  257. CQE_STATUS_COMPL_MASK;
  258. if (compl_status != MCC_STATUS_SUCCESS) {
  259. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  260. CQE_STATUS_EXTD_MASK;
  261. beiscsi_log(phba, KERN_ERR,
  262. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  263. "BC_%d : error in cmd completion: "
  264. "Subsystem : %d Opcode : %d "
  265. "status(compl/extd)=%d/%d\n",
  266. hdr->subsystem, hdr->opcode,
  267. compl_status, extd_status);
  268. if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  269. resp_hdr = (struct be_cmd_resp_hdr *) hdr;
  270. if (resp_hdr->response_length)
  271. return 0;
  272. }
  273. return -EBUSY;
  274. }
  275. return 0;
  276. }
  277. int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
  278. struct be_mcc_compl *compl)
  279. {
  280. u16 compl_status, extd_status;
  281. unsigned short tag;
  282. be_dws_le_to_cpu(compl, 4);
  283. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  284. CQE_STATUS_COMPL_MASK;
  285. /* The ctrl.mcc_numtag[tag] is filled with
  286. * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
  287. * [7:0] = compl_status
  288. */
  289. tag = (compl->tag0 & 0x000000FF);
  290. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  291. CQE_STATUS_EXTD_MASK;
  292. ctrl->mcc_numtag[tag] = 0x80000000;
  293. ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
  294. ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
  295. ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
  296. wake_up_interruptible(&ctrl->mcc_wait[tag]);
  297. return 0;
  298. }
  299. static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
  300. {
  301. struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
  302. struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
  303. if (be_mcc_compl_is_new(compl)) {
  304. queue_tail_inc(mcc_cq);
  305. return compl;
  306. }
  307. return NULL;
  308. }
  309. static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
  310. {
  311. iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
  312. }
  313. void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
  314. struct be_async_event_link_state *evt)
  315. {
  316. if ((evt->port_link_status == ASYNC_EVENT_LINK_DOWN) ||
  317. ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
  318. (evt->port_fault != BEISCSI_PHY_LINK_FAULT_NONE))) {
  319. phba->state = BE_ADAPTER_LINK_DOWN;
  320. beiscsi_log(phba, KERN_ERR,
  321. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  322. "BC_%d : Link Down on Port %d\n",
  323. evt->physical_port);
  324. iscsi_host_for_each_session(phba->shost,
  325. be2iscsi_fail_session);
  326. } else if ((evt->port_link_status & ASYNC_EVENT_LINK_UP) ||
  327. ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
  328. (evt->port_fault == BEISCSI_PHY_LINK_FAULT_NONE))) {
  329. phba->state = BE_ADAPTER_LINK_UP;
  330. beiscsi_log(phba, KERN_ERR,
  331. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  332. "BC_%d : Link UP on Port %d\n",
  333. evt->physical_port);
  334. }
  335. }
  336. static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm,
  337. u16 num_popped)
  338. {
  339. u32 val = 0;
  340. val |= qid & DB_CQ_RING_ID_MASK;
  341. if (arm)
  342. val |= 1 << DB_CQ_REARM_SHIFT;
  343. val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
  344. iowrite32(val, phba->db_va + DB_CQ_OFFSET);
  345. }
  346. int beiscsi_process_mcc(struct beiscsi_hba *phba)
  347. {
  348. struct be_mcc_compl *compl;
  349. int num = 0, status = 0;
  350. struct be_ctrl_info *ctrl = &phba->ctrl;
  351. spin_lock_bh(&phba->ctrl.mcc_cq_lock);
  352. while ((compl = be_mcc_compl_get(phba))) {
  353. if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
  354. /* Interpret flags as an async trailer */
  355. if (is_link_state_evt(compl->flags))
  356. /* Interpret compl as a async link evt */
  357. beiscsi_async_link_state_process(phba,
  358. (struct be_async_event_link_state *) compl);
  359. else
  360. beiscsi_log(phba, KERN_ERR,
  361. BEISCSI_LOG_CONFIG |
  362. BEISCSI_LOG_MBOX,
  363. "BC_%d : Unsupported Async Event, flags"
  364. " = 0x%08x\n", compl->flags);
  365. } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  366. status = be_mcc_compl_process(ctrl, compl);
  367. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  368. }
  369. be_mcc_compl_use(compl);
  370. num++;
  371. }
  372. if (num)
  373. beiscsi_cq_notify(phba, phba->ctrl.mcc_obj.cq.id, true, num);
  374. spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
  375. return status;
  376. }
  377. /*
  378. * be_mcc_wait_compl()- Wait for MBX completion
  379. * @phba: driver private structure
  380. *
  381. * Wait till no more pending mcc requests are present
  382. *
  383. * return
  384. * Success: 0
  385. * Failure: Non-Zero
  386. *
  387. **/
  388. static int be_mcc_wait_compl(struct beiscsi_hba *phba)
  389. {
  390. int i, status;
  391. for (i = 0; i < mcc_timeout; i++) {
  392. if (beiscsi_error(phba))
  393. return -EIO;
  394. status = beiscsi_process_mcc(phba);
  395. if (status)
  396. return status;
  397. if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
  398. break;
  399. udelay(100);
  400. }
  401. if (i == mcc_timeout) {
  402. beiscsi_log(phba, KERN_ERR,
  403. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  404. "BC_%d : FW Timed Out\n");
  405. phba->fw_timeout = true;
  406. beiscsi_ue_detect(phba);
  407. return -EBUSY;
  408. }
  409. return 0;
  410. }
  411. /*
  412. * be_mcc_notify_wait()- Notify and wait for Compl
  413. * @phba: driver private structure
  414. *
  415. * Notify MCC requests and wait for completion
  416. *
  417. * return
  418. * Success: 0
  419. * Failure: Non-Zero
  420. **/
  421. int be_mcc_notify_wait(struct beiscsi_hba *phba)
  422. {
  423. be_mcc_notify(phba);
  424. return be_mcc_wait_compl(phba);
  425. }
  426. /*
  427. * be_mbox_db_ready_wait()- Check ready status
  428. * @ctrl: Function specific MBX data structure
  429. *
  430. * Check for the ready status of FW to send BMBX
  431. * commands to adapter.
  432. *
  433. * return
  434. * Success: 0
  435. * Failure: Non-Zero
  436. **/
  437. static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
  438. {
  439. #define BEISCSI_MBX_RDY_BIT_TIMEOUT 4000 /* 4sec */
  440. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  441. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  442. unsigned long timeout;
  443. bool read_flag = false;
  444. int ret = 0, i;
  445. u32 ready;
  446. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(rdybit_check_q);
  447. if (beiscsi_error(phba))
  448. return -EIO;
  449. timeout = jiffies + (HZ * 110);
  450. do {
  451. for (i = 0; i < BEISCSI_MBX_RDY_BIT_TIMEOUT; i++) {
  452. ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
  453. if (ready) {
  454. read_flag = true;
  455. break;
  456. }
  457. mdelay(1);
  458. }
  459. if (!read_flag) {
  460. wait_event_timeout(rdybit_check_q,
  461. (read_flag != true),
  462. HZ * 5);
  463. }
  464. } while ((time_before(jiffies, timeout)) && !read_flag);
  465. if (!read_flag) {
  466. beiscsi_log(phba, KERN_ERR,
  467. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  468. "BC_%d : FW Timed Out\n");
  469. phba->fw_timeout = true;
  470. beiscsi_ue_detect(phba);
  471. ret = -EBUSY;
  472. }
  473. return ret;
  474. }
  475. /*
  476. * be_mbox_notify: Notify adapter of new BMBX command
  477. * @ctrl: Function specific MBX data structure
  478. *
  479. * Ring doorbell to inform adapter of a BMBX command
  480. * to process
  481. *
  482. * return
  483. * Success: 0
  484. * Failure: Non-Zero
  485. **/
  486. int be_mbox_notify(struct be_ctrl_info *ctrl)
  487. {
  488. int status;
  489. u32 val = 0;
  490. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  491. struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
  492. struct be_mcc_mailbox *mbox = mbox_mem->va;
  493. struct be_mcc_compl *compl = &mbox->compl;
  494. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  495. status = be_mbox_db_ready_wait(ctrl);
  496. if (status)
  497. return status;
  498. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  499. val |= MPU_MAILBOX_DB_HI_MASK;
  500. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  501. iowrite32(val, db);
  502. status = be_mbox_db_ready_wait(ctrl);
  503. if (status)
  504. return status;
  505. val = 0;
  506. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  507. val &= ~MPU_MAILBOX_DB_HI_MASK;
  508. val |= (u32) (mbox_mem->dma >> 4) << 2;
  509. iowrite32(val, db);
  510. status = be_mbox_db_ready_wait(ctrl);
  511. if (status)
  512. return status;
  513. if (be_mcc_compl_is_new(compl)) {
  514. status = be_mcc_compl_process(ctrl, &mbox->compl);
  515. be_mcc_compl_use(compl);
  516. if (status) {
  517. beiscsi_log(phba, KERN_ERR,
  518. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  519. "BC_%d : After be_mcc_compl_process\n");
  520. return status;
  521. }
  522. } else {
  523. beiscsi_log(phba, KERN_ERR,
  524. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  525. "BC_%d : Invalid Mailbox Completion\n");
  526. return -EBUSY;
  527. }
  528. return 0;
  529. }
  530. /*
  531. * Insert the mailbox address into the doorbell in two steps
  532. * Polls on the mbox doorbell till a command completion (or a timeout) occurs
  533. */
  534. static int be_mbox_notify_wait(struct beiscsi_hba *phba)
  535. {
  536. int status;
  537. u32 val = 0;
  538. void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
  539. struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
  540. struct be_mcc_mailbox *mbox = mbox_mem->va;
  541. struct be_mcc_compl *compl = &mbox->compl;
  542. struct be_ctrl_info *ctrl = &phba->ctrl;
  543. status = be_mbox_db_ready_wait(ctrl);
  544. if (status)
  545. return status;
  546. val |= MPU_MAILBOX_DB_HI_MASK;
  547. /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
  548. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  549. iowrite32(val, db);
  550. /* wait for ready to be set */
  551. status = be_mbox_db_ready_wait(ctrl);
  552. if (status != 0)
  553. return status;
  554. val = 0;
  555. /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
  556. val |= (u32)(mbox_mem->dma >> 4) << 2;
  557. iowrite32(val, db);
  558. status = be_mbox_db_ready_wait(ctrl);
  559. if (status != 0)
  560. return status;
  561. /* A cq entry has been made now */
  562. if (be_mcc_compl_is_new(compl)) {
  563. status = be_mcc_compl_process(ctrl, &mbox->compl);
  564. be_mcc_compl_use(compl);
  565. if (status)
  566. return status;
  567. } else {
  568. beiscsi_log(phba, KERN_ERR,
  569. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  570. "BC_%d : invalid mailbox completion\n");
  571. return -EBUSY;
  572. }
  573. return 0;
  574. }
  575. void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
  576. bool embedded, u8 sge_cnt)
  577. {
  578. if (embedded)
  579. wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
  580. else
  581. wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
  582. MCC_WRB_SGE_CNT_SHIFT;
  583. wrb->payload_length = payload_len;
  584. be_dws_cpu_to_le(wrb, 8);
  585. }
  586. void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
  587. u8 subsystem, u8 opcode, int cmd_len)
  588. {
  589. req_hdr->opcode = opcode;
  590. req_hdr->subsystem = subsystem;
  591. req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
  592. req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
  593. }
  594. static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
  595. struct be_dma_mem *mem)
  596. {
  597. int i, buf_pages;
  598. u64 dma = (u64) mem->dma;
  599. buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
  600. for (i = 0; i < buf_pages; i++) {
  601. pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
  602. pages[i].hi = cpu_to_le32(upper_32_bits(dma));
  603. dma += PAGE_SIZE_4K;
  604. }
  605. }
  606. static u32 eq_delay_to_mult(u32 usec_delay)
  607. {
  608. #define MAX_INTR_RATE 651042
  609. const u32 round = 10;
  610. u32 multiplier;
  611. if (usec_delay == 0)
  612. multiplier = 0;
  613. else {
  614. u32 interrupt_rate = 1000000 / usec_delay;
  615. if (interrupt_rate == 0)
  616. multiplier = 1023;
  617. else {
  618. multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
  619. multiplier /= interrupt_rate;
  620. multiplier = (multiplier + round / 2) / round;
  621. multiplier = min(multiplier, (u32) 1023);
  622. }
  623. }
  624. return multiplier;
  625. }
  626. struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
  627. {
  628. return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
  629. }
  630. struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
  631. {
  632. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  633. struct be_mcc_wrb *wrb;
  634. WARN_ON(atomic_read(&mccq->used) >= mccq->len);
  635. wrb = queue_head_node(mccq);
  636. memset(wrb, 0, sizeof(*wrb));
  637. wrb->tag0 = (mccq->head & 0x000000FF) << 16;
  638. queue_head_inc(mccq);
  639. atomic_inc(&mccq->used);
  640. return wrb;
  641. }
  642. int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
  643. struct be_queue_info *eq, int eq_delay)
  644. {
  645. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  646. struct be_cmd_req_eq_create *req = embedded_payload(wrb);
  647. struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
  648. struct be_dma_mem *q_mem = &eq->dma_mem;
  649. int status;
  650. spin_lock(&ctrl->mbox_lock);
  651. memset(wrb, 0, sizeof(*wrb));
  652. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  653. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  654. OPCODE_COMMON_EQ_CREATE, sizeof(*req));
  655. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  656. AMAP_SET_BITS(struct amap_eq_context, func, req->context,
  657. PCI_FUNC(ctrl->pdev->devfn));
  658. AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
  659. AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
  660. AMAP_SET_BITS(struct amap_eq_context, count, req->context,
  661. __ilog2_u32(eq->len / 256));
  662. AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
  663. eq_delay_to_mult(eq_delay));
  664. be_dws_cpu_to_le(req->context, sizeof(req->context));
  665. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  666. status = be_mbox_notify(ctrl);
  667. if (!status) {
  668. eq->id = le16_to_cpu(resp->eq_id);
  669. eq->created = true;
  670. }
  671. spin_unlock(&ctrl->mbox_lock);
  672. return status;
  673. }
  674. /**
  675. * be_cmd_fw_initialize()- Initialize FW
  676. * @ctrl: Pointer to function control structure
  677. *
  678. * Send FW initialize pattern for the function.
  679. *
  680. * return
  681. * Success: 0
  682. * Failure: Non-Zero value
  683. **/
  684. int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
  685. {
  686. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  687. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  688. int status;
  689. u8 *endian_check;
  690. spin_lock(&ctrl->mbox_lock);
  691. memset(wrb, 0, sizeof(*wrb));
  692. endian_check = (u8 *) wrb;
  693. *endian_check++ = 0xFF;
  694. *endian_check++ = 0x12;
  695. *endian_check++ = 0x34;
  696. *endian_check++ = 0xFF;
  697. *endian_check++ = 0xFF;
  698. *endian_check++ = 0x56;
  699. *endian_check++ = 0x78;
  700. *endian_check++ = 0xFF;
  701. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  702. status = be_mbox_notify(ctrl);
  703. if (status)
  704. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  705. "BC_%d : be_cmd_fw_initialize Failed\n");
  706. spin_unlock(&ctrl->mbox_lock);
  707. return status;
  708. }
  709. /**
  710. * be_cmd_fw_uninit()- Uinitialize FW
  711. * @ctrl: Pointer to function control structure
  712. *
  713. * Send FW uninitialize pattern for the function
  714. *
  715. * return
  716. * Success: 0
  717. * Failure: Non-Zero value
  718. **/
  719. int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
  720. {
  721. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  722. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  723. int status;
  724. u8 *endian_check;
  725. spin_lock(&ctrl->mbox_lock);
  726. memset(wrb, 0, sizeof(*wrb));
  727. endian_check = (u8 *) wrb;
  728. *endian_check++ = 0xFF;
  729. *endian_check++ = 0xAA;
  730. *endian_check++ = 0xBB;
  731. *endian_check++ = 0xFF;
  732. *endian_check++ = 0xFF;
  733. *endian_check++ = 0xCC;
  734. *endian_check++ = 0xDD;
  735. *endian_check = 0xFF;
  736. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  737. status = be_mbox_notify(ctrl);
  738. if (status)
  739. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  740. "BC_%d : be_cmd_fw_uninit Failed\n");
  741. spin_unlock(&ctrl->mbox_lock);
  742. return status;
  743. }
  744. int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
  745. struct be_queue_info *cq, struct be_queue_info *eq,
  746. bool sol_evts, bool no_delay, int coalesce_wm)
  747. {
  748. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  749. struct be_cmd_req_cq_create *req = embedded_payload(wrb);
  750. struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
  751. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  752. struct be_dma_mem *q_mem = &cq->dma_mem;
  753. void *ctxt = &req->context;
  754. int status;
  755. spin_lock(&ctrl->mbox_lock);
  756. memset(wrb, 0, sizeof(*wrb));
  757. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  758. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  759. OPCODE_COMMON_CQ_CREATE, sizeof(*req));
  760. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  761. if (is_chip_be2_be3r(phba)) {
  762. AMAP_SET_BITS(struct amap_cq_context, coalescwm,
  763. ctxt, coalesce_wm);
  764. AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
  765. AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
  766. __ilog2_u32(cq->len / 256));
  767. AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
  768. AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
  769. AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
  770. AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
  771. AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
  772. AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
  773. PCI_FUNC(ctrl->pdev->devfn));
  774. } else {
  775. req->hdr.version = MBX_CMD_VER2;
  776. req->page_size = 1;
  777. AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
  778. ctxt, coalesce_wm);
  779. AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
  780. ctxt, no_delay);
  781. AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
  782. __ilog2_u32(cq->len / 256));
  783. AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
  784. AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
  785. AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
  786. AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
  787. }
  788. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  789. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  790. status = be_mbox_notify(ctrl);
  791. if (!status) {
  792. cq->id = le16_to_cpu(resp->cq_id);
  793. cq->created = true;
  794. } else
  795. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  796. "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
  797. status);
  798. spin_unlock(&ctrl->mbox_lock);
  799. return status;
  800. }
  801. static u32 be_encoded_q_len(int q_len)
  802. {
  803. u32 len_encoded = fls(q_len); /* log2(len) + 1 */
  804. if (len_encoded == 16)
  805. len_encoded = 0;
  806. return len_encoded;
  807. }
  808. int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
  809. struct be_queue_info *mccq,
  810. struct be_queue_info *cq)
  811. {
  812. struct be_mcc_wrb *wrb;
  813. struct be_cmd_req_mcc_create *req;
  814. struct be_dma_mem *q_mem = &mccq->dma_mem;
  815. struct be_ctrl_info *ctrl;
  816. void *ctxt;
  817. int status;
  818. spin_lock(&phba->ctrl.mbox_lock);
  819. ctrl = &phba->ctrl;
  820. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  821. memset(wrb, 0, sizeof(*wrb));
  822. req = embedded_payload(wrb);
  823. ctxt = &req->context;
  824. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  825. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  826. OPCODE_COMMON_MCC_CREATE, sizeof(*req));
  827. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  828. AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
  829. PCI_FUNC(phba->pcidev->devfn));
  830. AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
  831. AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
  832. be_encoded_q_len(mccq->len));
  833. AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
  834. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  835. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  836. status = be_mbox_notify_wait(phba);
  837. if (!status) {
  838. struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
  839. mccq->id = le16_to_cpu(resp->id);
  840. mccq->created = true;
  841. }
  842. spin_unlock(&phba->ctrl.mbox_lock);
  843. return status;
  844. }
  845. int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
  846. int queue_type)
  847. {
  848. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  849. struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
  850. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  851. u8 subsys = 0, opcode = 0;
  852. int status;
  853. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  854. "BC_%d : In beiscsi_cmd_q_destroy "
  855. "queue_type : %d\n", queue_type);
  856. spin_lock(&ctrl->mbox_lock);
  857. memset(wrb, 0, sizeof(*wrb));
  858. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  859. switch (queue_type) {
  860. case QTYPE_EQ:
  861. subsys = CMD_SUBSYSTEM_COMMON;
  862. opcode = OPCODE_COMMON_EQ_DESTROY;
  863. break;
  864. case QTYPE_CQ:
  865. subsys = CMD_SUBSYSTEM_COMMON;
  866. opcode = OPCODE_COMMON_CQ_DESTROY;
  867. break;
  868. case QTYPE_MCCQ:
  869. subsys = CMD_SUBSYSTEM_COMMON;
  870. opcode = OPCODE_COMMON_MCC_DESTROY;
  871. break;
  872. case QTYPE_WRBQ:
  873. subsys = CMD_SUBSYSTEM_ISCSI;
  874. opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
  875. break;
  876. case QTYPE_DPDUQ:
  877. subsys = CMD_SUBSYSTEM_ISCSI;
  878. opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
  879. break;
  880. case QTYPE_SGL:
  881. subsys = CMD_SUBSYSTEM_ISCSI;
  882. opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
  883. break;
  884. default:
  885. spin_unlock(&ctrl->mbox_lock);
  886. BUG();
  887. return -ENXIO;
  888. }
  889. be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
  890. if (queue_type != QTYPE_SGL)
  891. req->id = cpu_to_le16(q->id);
  892. status = be_mbox_notify(ctrl);
  893. spin_unlock(&ctrl->mbox_lock);
  894. return status;
  895. }
  896. /**
  897. * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
  898. * @ctrl: ptr to ctrl_info
  899. * @cq: Completion Queue
  900. * @dq: Default Queue
  901. * @lenght: ring size
  902. * @entry_size: size of each entry in DEFQ
  903. * @is_header: Header or Data DEFQ
  904. * @ulp_num: Bind to which ULP
  905. *
  906. * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
  907. * on this queue by the FW
  908. *
  909. * return
  910. * Success: 0
  911. * Failure: Non-Zero Value
  912. *
  913. **/
  914. int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
  915. struct be_queue_info *cq,
  916. struct be_queue_info *dq, int length,
  917. int entry_size, uint8_t is_header,
  918. uint8_t ulp_num)
  919. {
  920. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  921. struct be_defq_create_req *req = embedded_payload(wrb);
  922. struct be_dma_mem *q_mem = &dq->dma_mem;
  923. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  924. void *ctxt = &req->context;
  925. int status;
  926. spin_lock(&ctrl->mbox_lock);
  927. memset(wrb, 0, sizeof(*wrb));
  928. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  929. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  930. OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
  931. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  932. if (phba->fw_config.dual_ulp_aware) {
  933. req->ulp_num = ulp_num;
  934. req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
  935. req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
  936. }
  937. if (is_chip_be2_be3r(phba)) {
  938. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  939. rx_pdid, ctxt, 0);
  940. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  941. rx_pdid_valid, ctxt, 1);
  942. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  943. pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
  944. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  945. ring_size, ctxt,
  946. be_encoded_q_len(length /
  947. sizeof(struct phys_addr)));
  948. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  949. default_buffer_size, ctxt, entry_size);
  950. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  951. cq_id_recv, ctxt, cq->id);
  952. } else {
  953. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  954. rx_pdid, ctxt, 0);
  955. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  956. rx_pdid_valid, ctxt, 1);
  957. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  958. ring_size, ctxt,
  959. be_encoded_q_len(length /
  960. sizeof(struct phys_addr)));
  961. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  962. default_buffer_size, ctxt, entry_size);
  963. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  964. cq_id_recv, ctxt, cq->id);
  965. }
  966. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  967. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  968. status = be_mbox_notify(ctrl);
  969. if (!status) {
  970. struct be_ring *defq_ring;
  971. struct be_defq_create_resp *resp = embedded_payload(wrb);
  972. dq->id = le16_to_cpu(resp->id);
  973. dq->created = true;
  974. if (is_header)
  975. defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
  976. else
  977. defq_ring = &phba->phwi_ctrlr->
  978. default_pdu_data[ulp_num];
  979. defq_ring->id = dq->id;
  980. if (!phba->fw_config.dual_ulp_aware) {
  981. defq_ring->ulp_num = BEISCSI_ULP0;
  982. defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
  983. } else {
  984. defq_ring->ulp_num = resp->ulp_num;
  985. defq_ring->doorbell_offset = resp->doorbell_offset;
  986. }
  987. }
  988. spin_unlock(&ctrl->mbox_lock);
  989. return status;
  990. }
  991. /**
  992. * be_cmd_wrbq_create()- Create WRBQ
  993. * @ctrl: ptr to ctrl_info
  994. * @q_mem: memory details for the queue
  995. * @wrbq: queue info
  996. * @pwrb_context: ptr to wrb_context
  997. * @ulp_num: ULP on which the WRBQ is to be created
  998. *
  999. * Create WRBQ on the passed ULP_NUM.
  1000. *
  1001. **/
  1002. int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
  1003. struct be_dma_mem *q_mem,
  1004. struct be_queue_info *wrbq,
  1005. struct hwi_wrb_context *pwrb_context,
  1006. uint8_t ulp_num)
  1007. {
  1008. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1009. struct be_wrbq_create_req *req = embedded_payload(wrb);
  1010. struct be_wrbq_create_resp *resp = embedded_payload(wrb);
  1011. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  1012. int status;
  1013. spin_lock(&ctrl->mbox_lock);
  1014. memset(wrb, 0, sizeof(*wrb));
  1015. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1016. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1017. OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
  1018. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  1019. if (phba->fw_config.dual_ulp_aware) {
  1020. req->ulp_num = ulp_num;
  1021. req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
  1022. req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
  1023. }
  1024. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  1025. status = be_mbox_notify(ctrl);
  1026. if (!status) {
  1027. wrbq->id = le16_to_cpu(resp->cid);
  1028. wrbq->created = true;
  1029. pwrb_context->cid = wrbq->id;
  1030. if (!phba->fw_config.dual_ulp_aware) {
  1031. pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
  1032. pwrb_context->ulp_num = BEISCSI_ULP0;
  1033. } else {
  1034. pwrb_context->ulp_num = resp->ulp_num;
  1035. pwrb_context->doorbell_offset = resp->doorbell_offset;
  1036. }
  1037. }
  1038. spin_unlock(&ctrl->mbox_lock);
  1039. return status;
  1040. }
  1041. int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
  1042. struct be_dma_mem *q_mem)
  1043. {
  1044. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1045. struct be_post_template_pages_req *req = embedded_payload(wrb);
  1046. int status;
  1047. spin_lock(&ctrl->mbox_lock);
  1048. memset(wrb, 0, sizeof(*wrb));
  1049. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1050. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1051. OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
  1052. sizeof(*req));
  1053. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  1054. req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
  1055. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  1056. status = be_mbox_notify(ctrl);
  1057. spin_unlock(&ctrl->mbox_lock);
  1058. return status;
  1059. }
  1060. int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
  1061. {
  1062. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1063. struct be_remove_template_pages_req *req = embedded_payload(wrb);
  1064. int status;
  1065. spin_lock(&ctrl->mbox_lock);
  1066. memset(wrb, 0, sizeof(*wrb));
  1067. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1068. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1069. OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
  1070. sizeof(*req));
  1071. req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
  1072. status = be_mbox_notify(ctrl);
  1073. spin_unlock(&ctrl->mbox_lock);
  1074. return status;
  1075. }
  1076. int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
  1077. struct be_dma_mem *q_mem,
  1078. u32 page_offset, u32 num_pages)
  1079. {
  1080. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1081. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  1082. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  1083. int status;
  1084. unsigned int curr_pages;
  1085. u32 internal_page_offset = 0;
  1086. u32 temp_num_pages = num_pages;
  1087. if (num_pages == 0xff)
  1088. num_pages = 1;
  1089. spin_lock(&ctrl->mbox_lock);
  1090. do {
  1091. memset(wrb, 0, sizeof(*wrb));
  1092. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1093. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1094. OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
  1095. sizeof(*req));
  1096. curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
  1097. pages);
  1098. req->num_pages = min(num_pages, curr_pages);
  1099. req->page_offset = page_offset;
  1100. be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
  1101. q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
  1102. internal_page_offset += req->num_pages;
  1103. page_offset += req->num_pages;
  1104. num_pages -= req->num_pages;
  1105. if (temp_num_pages == 0xff)
  1106. req->num_pages = temp_num_pages;
  1107. status = be_mbox_notify(ctrl);
  1108. if (status) {
  1109. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1110. "BC_%d : FW CMD to map iscsi frags failed.\n");
  1111. goto error;
  1112. }
  1113. } while (num_pages > 0);
  1114. error:
  1115. spin_unlock(&ctrl->mbox_lock);
  1116. if (status != 0)
  1117. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  1118. return status;
  1119. }
  1120. int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
  1121. {
  1122. struct be_ctrl_info *ctrl = &phba->ctrl;
  1123. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1124. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  1125. int status;
  1126. spin_lock(&ctrl->mbox_lock);
  1127. req = embedded_payload(wrb);
  1128. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1129. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1130. OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
  1131. status = be_mbox_notify_wait(phba);
  1132. spin_unlock(&ctrl->mbox_lock);
  1133. return status;
  1134. }
  1135. /**
  1136. * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
  1137. * @phba: device priv structure instance
  1138. * @vlan_tag: TAG to be set
  1139. *
  1140. * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
  1141. *
  1142. * returns
  1143. * TAG for the MBX Cmd
  1144. * **/
  1145. int be_cmd_set_vlan(struct beiscsi_hba *phba,
  1146. uint16_t vlan_tag)
  1147. {
  1148. unsigned int tag = 0;
  1149. struct be_mcc_wrb *wrb;
  1150. struct be_cmd_set_vlan_req *req;
  1151. struct be_ctrl_info *ctrl = &phba->ctrl;
  1152. spin_lock(&ctrl->mbox_lock);
  1153. tag = alloc_mcc_tag(phba);
  1154. if (!tag) {
  1155. spin_unlock(&ctrl->mbox_lock);
  1156. return tag;
  1157. }
  1158. wrb = wrb_from_mccq(phba);
  1159. req = embedded_payload(wrb);
  1160. wrb->tag0 |= tag;
  1161. be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
  1162. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1163. OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
  1164. sizeof(*req));
  1165. req->interface_hndl = phba->interface_handle;
  1166. req->vlan_priority = vlan_tag;
  1167. be_mcc_notify(phba);
  1168. spin_unlock(&ctrl->mbox_lock);
  1169. return tag;
  1170. }