be_mgmt.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779
  1. /**
  2. * Copyright (C) 2005 - 2015 Avago Technologies
  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. * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com)
  11. *
  12. * Contact Information:
  13. * linux-drivers@avagotech.com
  14. *
  15. * Avago Technologies
  16. * 3333 Susan Street
  17. * Costa Mesa, CA 92626
  18. */
  19. #include <linux/bsg-lib.h>
  20. #include <scsi/scsi_transport_iscsi.h>
  21. #include <scsi/scsi_bsg_iscsi.h>
  22. #include "be_mgmt.h"
  23. #include "be_iscsi.h"
  24. #include "be_main.h"
  25. /* UE Status Low CSR */
  26. static const char * const desc_ue_status_low[] = {
  27. "CEV",
  28. "CTX",
  29. "DBUF",
  30. "ERX",
  31. "Host",
  32. "MPU",
  33. "NDMA",
  34. "PTC ",
  35. "RDMA ",
  36. "RXF ",
  37. "RXIPS ",
  38. "RXULP0 ",
  39. "RXULP1 ",
  40. "RXULP2 ",
  41. "TIM ",
  42. "TPOST ",
  43. "TPRE ",
  44. "TXIPS ",
  45. "TXULP0 ",
  46. "TXULP1 ",
  47. "UC ",
  48. "WDMA ",
  49. "TXULP2 ",
  50. "HOST1 ",
  51. "P0_OB_LINK ",
  52. "P1_OB_LINK ",
  53. "HOST_GPIO ",
  54. "MBOX ",
  55. "AXGMAC0",
  56. "AXGMAC1",
  57. "JTAG",
  58. "MPU_INTPEND"
  59. };
  60. /* UE Status High CSR */
  61. static const char * const desc_ue_status_hi[] = {
  62. "LPCMEMHOST",
  63. "MGMT_MAC",
  64. "PCS0ONLINE",
  65. "MPU_IRAM",
  66. "PCS1ONLINE",
  67. "PCTL0",
  68. "PCTL1",
  69. "PMEM",
  70. "RR",
  71. "TXPB",
  72. "RXPP",
  73. "XAUI",
  74. "TXP",
  75. "ARM",
  76. "IPC",
  77. "HOST2",
  78. "HOST3",
  79. "HOST4",
  80. "HOST5",
  81. "HOST6",
  82. "HOST7",
  83. "HOST8",
  84. "HOST9",
  85. "NETC",
  86. "Unknown",
  87. "Unknown",
  88. "Unknown",
  89. "Unknown",
  90. "Unknown",
  91. "Unknown",
  92. "Unknown",
  93. "Unknown"
  94. };
  95. /*
  96. * beiscsi_ue_detec()- Detect Unrecoverable Error on adapter
  97. * @phba: Driver priv structure
  98. *
  99. * Read registers linked to UE and check for the UE status
  100. **/
  101. void beiscsi_ue_detect(struct beiscsi_hba *phba)
  102. {
  103. uint32_t ue_hi = 0, ue_lo = 0;
  104. uint32_t ue_mask_hi = 0, ue_mask_lo = 0;
  105. uint8_t i = 0;
  106. if (phba->ue_detected)
  107. return;
  108. pci_read_config_dword(phba->pcidev,
  109. PCICFG_UE_STATUS_LOW, &ue_lo);
  110. pci_read_config_dword(phba->pcidev,
  111. PCICFG_UE_STATUS_MASK_LOW,
  112. &ue_mask_lo);
  113. pci_read_config_dword(phba->pcidev,
  114. PCICFG_UE_STATUS_HIGH,
  115. &ue_hi);
  116. pci_read_config_dword(phba->pcidev,
  117. PCICFG_UE_STATUS_MASK_HI,
  118. &ue_mask_hi);
  119. ue_lo = (ue_lo & ~ue_mask_lo);
  120. ue_hi = (ue_hi & ~ue_mask_hi);
  121. if (ue_lo || ue_hi) {
  122. phba->ue_detected = true;
  123. beiscsi_log(phba, KERN_ERR,
  124. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  125. "BG_%d : Error detected on the adapter\n");
  126. }
  127. if (ue_lo) {
  128. for (i = 0; ue_lo; ue_lo >>= 1, i++) {
  129. if (ue_lo & 1)
  130. beiscsi_log(phba, KERN_ERR,
  131. BEISCSI_LOG_CONFIG,
  132. "BG_%d : UE_LOW %s bit set\n",
  133. desc_ue_status_low[i]);
  134. }
  135. }
  136. if (ue_hi) {
  137. for (i = 0; ue_hi; ue_hi >>= 1, i++) {
  138. if (ue_hi & 1)
  139. beiscsi_log(phba, KERN_ERR,
  140. BEISCSI_LOG_CONFIG,
  141. "BG_%d : UE_HIGH %s bit set\n",
  142. desc_ue_status_hi[i]);
  143. }
  144. }
  145. }
  146. int be_cmd_modify_eq_delay(struct beiscsi_hba *phba,
  147. struct be_set_eqd *set_eqd, int num)
  148. {
  149. struct be_ctrl_info *ctrl = &phba->ctrl;
  150. struct be_mcc_wrb *wrb;
  151. struct be_cmd_req_modify_eq_delay *req;
  152. unsigned int tag = 0;
  153. int i;
  154. spin_lock(&ctrl->mbox_lock);
  155. tag = alloc_mcc_tag(phba);
  156. if (!tag) {
  157. spin_unlock(&ctrl->mbox_lock);
  158. return tag;
  159. }
  160. wrb = wrb_from_mccq(phba);
  161. req = embedded_payload(wrb);
  162. wrb->tag0 |= tag;
  163. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  164. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  165. OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
  166. req->num_eq = cpu_to_le32(num);
  167. for (i = 0; i < num; i++) {
  168. req->delay[i].eq_id = cpu_to_le32(set_eqd[i].eq_id);
  169. req->delay[i].phase = 0;
  170. req->delay[i].delay_multiplier =
  171. cpu_to_le32(set_eqd[i].delay_multiplier);
  172. }
  173. be_mcc_notify(phba);
  174. spin_unlock(&ctrl->mbox_lock);
  175. return tag;
  176. }
  177. /**
  178. * mgmt_reopen_session()- Reopen a session based on reopen_type
  179. * @phba: Device priv structure instance
  180. * @reopen_type: Type of reopen_session FW should do.
  181. * @sess_handle: Session Handle of the session to be re-opened
  182. *
  183. * return
  184. * the TAG used for MBOX Command
  185. *
  186. **/
  187. unsigned int mgmt_reopen_session(struct beiscsi_hba *phba,
  188. unsigned int reopen_type,
  189. unsigned int sess_handle)
  190. {
  191. struct be_ctrl_info *ctrl = &phba->ctrl;
  192. struct be_mcc_wrb *wrb;
  193. struct be_cmd_reopen_session_req *req;
  194. unsigned int tag = 0;
  195. beiscsi_log(phba, KERN_INFO,
  196. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  197. "BG_%d : In bescsi_get_boot_target\n");
  198. spin_lock(&ctrl->mbox_lock);
  199. tag = alloc_mcc_tag(phba);
  200. if (!tag) {
  201. spin_unlock(&ctrl->mbox_lock);
  202. return tag;
  203. }
  204. wrb = wrb_from_mccq(phba);
  205. req = embedded_payload(wrb);
  206. wrb->tag0 |= tag;
  207. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  208. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  209. OPCODE_ISCSI_INI_DRIVER_REOPEN_ALL_SESSIONS,
  210. sizeof(struct be_cmd_reopen_session_resp));
  211. /* set the reopen_type,sess_handle */
  212. req->reopen_type = reopen_type;
  213. req->session_handle = sess_handle;
  214. be_mcc_notify(phba);
  215. spin_unlock(&ctrl->mbox_lock);
  216. return tag;
  217. }
  218. unsigned int mgmt_get_boot_target(struct beiscsi_hba *phba)
  219. {
  220. struct be_ctrl_info *ctrl = &phba->ctrl;
  221. struct be_mcc_wrb *wrb;
  222. struct be_cmd_get_boot_target_req *req;
  223. unsigned int tag = 0;
  224. beiscsi_log(phba, KERN_INFO,
  225. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  226. "BG_%d : In bescsi_get_boot_target\n");
  227. spin_lock(&ctrl->mbox_lock);
  228. tag = alloc_mcc_tag(phba);
  229. if (!tag) {
  230. spin_unlock(&ctrl->mbox_lock);
  231. return tag;
  232. }
  233. wrb = wrb_from_mccq(phba);
  234. req = embedded_payload(wrb);
  235. wrb->tag0 |= tag;
  236. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  237. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  238. OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET,
  239. sizeof(struct be_cmd_get_boot_target_resp));
  240. be_mcc_notify(phba);
  241. spin_unlock(&ctrl->mbox_lock);
  242. return tag;
  243. }
  244. unsigned int mgmt_get_session_info(struct beiscsi_hba *phba,
  245. u32 boot_session_handle,
  246. struct be_dma_mem *nonemb_cmd)
  247. {
  248. struct be_ctrl_info *ctrl = &phba->ctrl;
  249. struct be_mcc_wrb *wrb;
  250. unsigned int tag = 0;
  251. struct be_cmd_get_session_req *req;
  252. struct be_cmd_get_session_resp *resp;
  253. struct be_sge *sge;
  254. beiscsi_log(phba, KERN_INFO,
  255. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  256. "BG_%d : In beiscsi_get_session_info\n");
  257. spin_lock(&ctrl->mbox_lock);
  258. tag = alloc_mcc_tag(phba);
  259. if (!tag) {
  260. spin_unlock(&ctrl->mbox_lock);
  261. return tag;
  262. }
  263. nonemb_cmd->size = sizeof(*resp);
  264. req = nonemb_cmd->va;
  265. memset(req, 0, sizeof(*req));
  266. wrb = wrb_from_mccq(phba);
  267. sge = nonembedded_sgl(wrb);
  268. wrb->tag0 |= tag;
  269. wrb->tag0 |= tag;
  270. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  271. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  272. OPCODE_ISCSI_INI_SESSION_GET_A_SESSION,
  273. sizeof(*resp));
  274. req->session_handle = boot_session_handle;
  275. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  276. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  277. sge->len = cpu_to_le32(nonemb_cmd->size);
  278. be_mcc_notify(phba);
  279. spin_unlock(&ctrl->mbox_lock);
  280. return tag;
  281. }
  282. /**
  283. * mgmt_get_fw_config()- Get the FW config for the function
  284. * @ctrl: ptr to Ctrl Info
  285. * @phba: ptr to the dev priv structure
  286. *
  287. * Get the FW config and resources available for the function.
  288. * The resources are created based on the count received here.
  289. *
  290. * return
  291. * Success: 0
  292. * Failure: Non-Zero Value
  293. **/
  294. int mgmt_get_fw_config(struct be_ctrl_info *ctrl,
  295. struct beiscsi_hba *phba)
  296. {
  297. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  298. struct be_fw_cfg *req = embedded_payload(wrb);
  299. int status = 0;
  300. spin_lock(&ctrl->mbox_lock);
  301. memset(wrb, 0, sizeof(*wrb));
  302. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  303. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  304. OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
  305. EMBED_MBX_MAX_PAYLOAD_SIZE);
  306. status = be_mbox_notify(ctrl);
  307. if (!status) {
  308. uint8_t ulp_num = 0;
  309. struct be_fw_cfg *pfw_cfg;
  310. pfw_cfg = req;
  311. if (!is_chip_be2_be3r(phba)) {
  312. phba->fw_config.eqid_count = pfw_cfg->eqid_count;
  313. phba->fw_config.cqid_count = pfw_cfg->cqid_count;
  314. beiscsi_log(phba, KERN_INFO,
  315. BEISCSI_LOG_INIT,
  316. "BG_%d : EQ_Count : %d CQ_Count : %d\n",
  317. phba->fw_config.eqid_count,
  318. phba->fw_config.cqid_count);
  319. }
  320. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
  321. if (pfw_cfg->ulp[ulp_num].ulp_mode &
  322. BEISCSI_ULP_ISCSI_INI_MODE)
  323. set_bit(ulp_num,
  324. &phba->fw_config.ulp_supported);
  325. phba->fw_config.phys_port = pfw_cfg->phys_port;
  326. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  327. if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
  328. phba->fw_config.iscsi_cid_start[ulp_num] =
  329. pfw_cfg->ulp[ulp_num].sq_base;
  330. phba->fw_config.iscsi_cid_count[ulp_num] =
  331. pfw_cfg->ulp[ulp_num].sq_count;
  332. phba->fw_config.iscsi_icd_start[ulp_num] =
  333. pfw_cfg->ulp[ulp_num].icd_base;
  334. phba->fw_config.iscsi_icd_count[ulp_num] =
  335. pfw_cfg->ulp[ulp_num].icd_count;
  336. phba->fw_config.iscsi_chain_start[ulp_num] =
  337. pfw_cfg->chain_icd[ulp_num].chain_base;
  338. phba->fw_config.iscsi_chain_count[ulp_num] =
  339. pfw_cfg->chain_icd[ulp_num].chain_count;
  340. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  341. "BG_%d : Function loaded on ULP : %d\n"
  342. "\tiscsi_cid_count : %d\n"
  343. "\tiscsi_cid_start : %d\n"
  344. "\t iscsi_icd_count : %d\n"
  345. "\t iscsi_icd_start : %d\n",
  346. ulp_num,
  347. phba->fw_config.
  348. iscsi_cid_count[ulp_num],
  349. phba->fw_config.
  350. iscsi_cid_start[ulp_num],
  351. phba->fw_config.
  352. iscsi_icd_count[ulp_num],
  353. phba->fw_config.
  354. iscsi_icd_start[ulp_num]);
  355. }
  356. }
  357. phba->fw_config.dual_ulp_aware = (pfw_cfg->function_mode &
  358. BEISCSI_FUNC_DUA_MODE);
  359. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  360. "BG_%d : DUA Mode : 0x%x\n",
  361. phba->fw_config.dual_ulp_aware);
  362. } else {
  363. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  364. "BG_%d : Failed in mgmt_get_fw_config\n");
  365. status = -EINVAL;
  366. }
  367. spin_unlock(&ctrl->mbox_lock);
  368. return status;
  369. }
  370. int mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
  371. struct beiscsi_hba *phba)
  372. {
  373. struct be_dma_mem nonemb_cmd;
  374. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  375. struct be_mgmt_controller_attributes *req;
  376. struct be_sge *sge = nonembedded_sgl(wrb);
  377. int status = 0;
  378. nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
  379. sizeof(struct be_mgmt_controller_attributes),
  380. &nonemb_cmd.dma);
  381. if (nonemb_cmd.va == NULL) {
  382. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  383. "BG_%d : Failed to allocate memory for "
  384. "mgmt_check_supported_fw\n");
  385. return -ENOMEM;
  386. }
  387. nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
  388. req = nonemb_cmd.va;
  389. memset(req, 0, sizeof(*req));
  390. spin_lock(&ctrl->mbox_lock);
  391. memset(wrb, 0, sizeof(*wrb));
  392. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  393. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  394. OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
  395. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
  396. sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
  397. sge->len = cpu_to_le32(nonemb_cmd.size);
  398. status = be_mbox_notify(ctrl);
  399. if (!status) {
  400. struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
  401. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  402. "BG_%d : Firmware Version of CMD : %s\n"
  403. "Firmware Version is : %s\n"
  404. "Developer Build, not performing version check...\n",
  405. resp->params.hba_attribs
  406. .flashrom_version_string,
  407. resp->params.hba_attribs.
  408. firmware_version_string);
  409. phba->fw_config.iscsi_features =
  410. resp->params.hba_attribs.iscsi_features;
  411. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  412. "BM_%d : phba->fw_config.iscsi_features = %d\n",
  413. phba->fw_config.iscsi_features);
  414. memcpy(phba->fw_ver_str, resp->params.hba_attribs.
  415. firmware_version_string, BEISCSI_VER_STRLEN);
  416. } else
  417. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  418. "BG_%d : Failed in mgmt_check_supported_fw\n");
  419. spin_unlock(&ctrl->mbox_lock);
  420. if (nonemb_cmd.va)
  421. pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
  422. nonemb_cmd.va, nonemb_cmd.dma);
  423. return status;
  424. }
  425. unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl,
  426. struct beiscsi_hba *phba,
  427. struct bsg_job *job,
  428. struct be_dma_mem *nonemb_cmd)
  429. {
  430. struct be_cmd_resp_hdr *resp;
  431. struct be_mcc_wrb *wrb;
  432. struct be_sge *mcc_sge;
  433. unsigned int tag = 0;
  434. struct iscsi_bsg_request *bsg_req = job->request;
  435. struct be_bsg_vendor_cmd *req = nonemb_cmd->va;
  436. unsigned short region, sector_size, sector, offset;
  437. nonemb_cmd->size = job->request_payload.payload_len;
  438. memset(nonemb_cmd->va, 0, nonemb_cmd->size);
  439. resp = nonemb_cmd->va;
  440. region = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
  441. sector_size = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
  442. sector = bsg_req->rqst_data.h_vendor.vendor_cmd[3];
  443. offset = bsg_req->rqst_data.h_vendor.vendor_cmd[4];
  444. req->region = region;
  445. req->sector = sector;
  446. req->offset = offset;
  447. spin_lock(&ctrl->mbox_lock);
  448. switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) {
  449. case BEISCSI_WRITE_FLASH:
  450. offset = sector * sector_size + offset;
  451. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  452. OPCODE_COMMON_WRITE_FLASH, sizeof(*req));
  453. sg_copy_to_buffer(job->request_payload.sg_list,
  454. job->request_payload.sg_cnt,
  455. nonemb_cmd->va + offset, job->request_len);
  456. break;
  457. case BEISCSI_READ_FLASH:
  458. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  459. OPCODE_COMMON_READ_FLASH, sizeof(*req));
  460. break;
  461. default:
  462. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  463. "BG_%d : Unsupported cmd = 0x%x\n\n",
  464. bsg_req->rqst_data.h_vendor.vendor_cmd[0]);
  465. spin_unlock(&ctrl->mbox_lock);
  466. return -ENOSYS;
  467. }
  468. tag = alloc_mcc_tag(phba);
  469. if (!tag) {
  470. spin_unlock(&ctrl->mbox_lock);
  471. return tag;
  472. }
  473. wrb = wrb_from_mccq(phba);
  474. mcc_sge = nonembedded_sgl(wrb);
  475. be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false,
  476. job->request_payload.sg_cnt);
  477. mcc_sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  478. mcc_sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  479. mcc_sge->len = cpu_to_le32(nonemb_cmd->size);
  480. wrb->tag0 |= tag;
  481. be_mcc_notify(phba);
  482. spin_unlock(&ctrl->mbox_lock);
  483. return tag;
  484. }
  485. /**
  486. * mgmt_epfw_cleanup()- Inform FW to cleanup data structures.
  487. * @phba: pointer to dev priv structure
  488. * @ulp_num: ULP number.
  489. *
  490. * return
  491. * Success: 0
  492. * Failure: Non-Zero Value
  493. **/
  494. int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short ulp_num)
  495. {
  496. struct be_ctrl_info *ctrl = &phba->ctrl;
  497. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  498. struct iscsi_cleanup_req *req = embedded_payload(wrb);
  499. int status = 0;
  500. spin_lock(&ctrl->mbox_lock);
  501. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  502. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  503. OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
  504. req->chute = (1 << ulp_num);
  505. req->hdr_ring_id = cpu_to_le16(HWI_GET_DEF_HDRQ_ID(phba, ulp_num));
  506. req->data_ring_id = cpu_to_le16(HWI_GET_DEF_BUFQ_ID(phba, ulp_num));
  507. status = be_mcc_notify_wait(phba);
  508. if (status)
  509. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  510. "BG_%d : mgmt_epfw_cleanup , FAILED\n");
  511. spin_unlock(&ctrl->mbox_lock);
  512. return status;
  513. }
  514. unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
  515. struct invalidate_command_table *inv_tbl,
  516. unsigned int num_invalidate, unsigned int cid,
  517. struct be_dma_mem *nonemb_cmd)
  518. {
  519. struct be_ctrl_info *ctrl = &phba->ctrl;
  520. struct be_mcc_wrb *wrb;
  521. struct be_sge *sge;
  522. struct invalidate_commands_params_in *req;
  523. unsigned int i, tag = 0;
  524. spin_lock(&ctrl->mbox_lock);
  525. tag = alloc_mcc_tag(phba);
  526. if (!tag) {
  527. spin_unlock(&ctrl->mbox_lock);
  528. return tag;
  529. }
  530. req = nonemb_cmd->va;
  531. memset(req, 0, sizeof(*req));
  532. wrb = wrb_from_mccq(phba);
  533. sge = nonembedded_sgl(wrb);
  534. wrb->tag0 |= tag;
  535. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  536. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  537. OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
  538. sizeof(*req));
  539. req->ref_handle = 0;
  540. req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
  541. for (i = 0; i < num_invalidate; i++) {
  542. req->table[i].icd = inv_tbl->icd;
  543. req->table[i].cid = inv_tbl->cid;
  544. req->icd_count++;
  545. inv_tbl++;
  546. }
  547. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  548. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  549. sge->len = cpu_to_le32(nonemb_cmd->size);
  550. be_mcc_notify(phba);
  551. spin_unlock(&ctrl->mbox_lock);
  552. return tag;
  553. }
  554. unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba,
  555. struct beiscsi_endpoint *beiscsi_ep,
  556. unsigned short cid,
  557. unsigned short issue_reset,
  558. unsigned short savecfg_flag)
  559. {
  560. struct be_ctrl_info *ctrl = &phba->ctrl;
  561. struct be_mcc_wrb *wrb;
  562. struct iscsi_invalidate_connection_params_in *req;
  563. unsigned int tag = 0;
  564. spin_lock(&ctrl->mbox_lock);
  565. tag = alloc_mcc_tag(phba);
  566. if (!tag) {
  567. spin_unlock(&ctrl->mbox_lock);
  568. return tag;
  569. }
  570. wrb = wrb_from_mccq(phba);
  571. wrb->tag0 |= tag;
  572. req = embedded_payload(wrb);
  573. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  574. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  575. OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
  576. sizeof(*req));
  577. req->session_handle = beiscsi_ep->fw_handle;
  578. req->cid = cid;
  579. if (issue_reset)
  580. req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
  581. else
  582. req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
  583. req->save_cfg = savecfg_flag;
  584. be_mcc_notify(phba);
  585. spin_unlock(&ctrl->mbox_lock);
  586. return tag;
  587. }
  588. unsigned int mgmt_upload_connection(struct beiscsi_hba *phba,
  589. unsigned short cid, unsigned int upload_flag)
  590. {
  591. struct be_ctrl_info *ctrl = &phba->ctrl;
  592. struct be_mcc_wrb *wrb;
  593. struct tcp_upload_params_in *req;
  594. unsigned int tag = 0;
  595. spin_lock(&ctrl->mbox_lock);
  596. tag = alloc_mcc_tag(phba);
  597. if (!tag) {
  598. spin_unlock(&ctrl->mbox_lock);
  599. return tag;
  600. }
  601. wrb = wrb_from_mccq(phba);
  602. req = embedded_payload(wrb);
  603. wrb->tag0 |= tag;
  604. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  605. be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
  606. OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
  607. req->id = (unsigned short)cid;
  608. req->upload_type = (unsigned char)upload_flag;
  609. be_mcc_notify(phba);
  610. spin_unlock(&ctrl->mbox_lock);
  611. return tag;
  612. }
  613. /**
  614. * mgmt_open_connection()- Establish a TCP CXN
  615. * @dst_addr: Destination Address
  616. * @beiscsi_ep: ptr to device endpoint struct
  617. * @nonemb_cmd: ptr to memory allocated for command
  618. *
  619. * return
  620. * Success: Tag number of the MBX Command issued
  621. * Failure: Error code
  622. **/
  623. int mgmt_open_connection(struct beiscsi_hba *phba,
  624. struct sockaddr *dst_addr,
  625. struct beiscsi_endpoint *beiscsi_ep,
  626. struct be_dma_mem *nonemb_cmd)
  627. {
  628. struct hwi_controller *phwi_ctrlr;
  629. struct hwi_context_memory *phwi_context;
  630. struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
  631. struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
  632. struct be_ctrl_info *ctrl = &phba->ctrl;
  633. struct be_mcc_wrb *wrb;
  634. struct tcp_connect_and_offload_in_v1 *req;
  635. unsigned short def_hdr_id;
  636. unsigned short def_data_id;
  637. struct phys_addr template_address = { 0, 0 };
  638. struct phys_addr *ptemplate_address;
  639. unsigned int tag = 0;
  640. unsigned int i, ulp_num;
  641. unsigned short cid = beiscsi_ep->ep_cid;
  642. struct be_sge *sge;
  643. phwi_ctrlr = phba->phwi_ctrlr;
  644. phwi_context = phwi_ctrlr->phwi_ctxt;
  645. ulp_num = phwi_ctrlr->wrb_context[BE_GET_CRI_FROM_CID(cid)].ulp_num;
  646. def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba, ulp_num);
  647. def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba, ulp_num);
  648. ptemplate_address = &template_address;
  649. ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
  650. spin_lock(&ctrl->mbox_lock);
  651. tag = alloc_mcc_tag(phba);
  652. if (!tag) {
  653. spin_unlock(&ctrl->mbox_lock);
  654. return tag;
  655. }
  656. wrb = wrb_from_mccq(phba);
  657. sge = nonembedded_sgl(wrb);
  658. req = nonemb_cmd->va;
  659. memset(req, 0, sizeof(*req));
  660. wrb->tag0 |= tag;
  661. be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1);
  662. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  663. OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
  664. nonemb_cmd->size);
  665. if (dst_addr->sa_family == PF_INET) {
  666. __be32 s_addr = daddr_in->sin_addr.s_addr;
  667. req->ip_address.ip_type = BE2_IPV4;
  668. req->ip_address.addr[0] = s_addr & 0x000000ff;
  669. req->ip_address.addr[1] = (s_addr & 0x0000ff00) >> 8;
  670. req->ip_address.addr[2] = (s_addr & 0x00ff0000) >> 16;
  671. req->ip_address.addr[3] = (s_addr & 0xff000000) >> 24;
  672. req->tcp_port = ntohs(daddr_in->sin_port);
  673. beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
  674. beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
  675. beiscsi_ep->ip_type = BE2_IPV4;
  676. } else if (dst_addr->sa_family == PF_INET6) {
  677. req->ip_address.ip_type = BE2_IPV6;
  678. memcpy(&req->ip_address.addr,
  679. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  680. req->tcp_port = ntohs(daddr_in6->sin6_port);
  681. beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
  682. memcpy(&beiscsi_ep->dst6_addr,
  683. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  684. beiscsi_ep->ip_type = BE2_IPV6;
  685. } else{
  686. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  687. "BG_%d : unknown addr family %d\n",
  688. dst_addr->sa_family);
  689. spin_unlock(&ctrl->mbox_lock);
  690. free_mcc_tag(&phba->ctrl, tag);
  691. return -EINVAL;
  692. }
  693. req->cid = cid;
  694. i = phba->nxt_cqid++;
  695. if (phba->nxt_cqid == phba->num_cpus)
  696. phba->nxt_cqid = 0;
  697. req->cq_id = phwi_context->be_cq[i].id;
  698. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  699. "BG_%d : i=%d cq_id=%d\n", i, req->cq_id);
  700. req->defq_id = def_hdr_id;
  701. req->hdr_ring_id = def_hdr_id;
  702. req->data_ring_id = def_data_id;
  703. req->do_offload = 1;
  704. req->dataout_template_pa.lo = ptemplate_address->lo;
  705. req->dataout_template_pa.hi = ptemplate_address->hi;
  706. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  707. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  708. sge->len = cpu_to_le32(nonemb_cmd->size);
  709. if (!is_chip_be2_be3r(phba)) {
  710. req->hdr.version = MBX_CMD_VER1;
  711. req->tcp_window_size = 0;
  712. req->tcp_window_scale_count = 2;
  713. }
  714. be_mcc_notify(phba);
  715. spin_unlock(&ctrl->mbox_lock);
  716. return tag;
  717. }
  718. unsigned int mgmt_get_all_if_id(struct beiscsi_hba *phba)
  719. {
  720. struct be_ctrl_info *ctrl = &phba->ctrl;
  721. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  722. struct be_cmd_get_all_if_id_req *req = embedded_payload(wrb);
  723. struct be_cmd_get_all_if_id_req *pbe_allid = req;
  724. int status = 0;
  725. memset(wrb, 0, sizeof(*wrb));
  726. spin_lock(&ctrl->mbox_lock);
  727. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  728. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  729. OPCODE_COMMON_ISCSI_NTWK_GET_ALL_IF_ID,
  730. sizeof(*req));
  731. status = be_mbox_notify(ctrl);
  732. if (!status)
  733. phba->interface_handle = pbe_allid->if_hndl_list[0];
  734. else {
  735. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  736. "BG_%d : Failed in mgmt_get_all_if_id\n");
  737. }
  738. spin_unlock(&ctrl->mbox_lock);
  739. return status;
  740. }
  741. /*
  742. * mgmt_exec_nonemb_cmd()- Execute Non Embedded MBX Cmd
  743. * @phba: Driver priv structure
  744. * @nonemb_cmd: Address of the MBX command issued
  745. * @resp_buf: Buffer to copy the MBX cmd response
  746. * @resp_buf_len: respone lenght to be copied
  747. *
  748. **/
  749. static int mgmt_exec_nonemb_cmd(struct beiscsi_hba *phba,
  750. struct be_dma_mem *nonemb_cmd, void *resp_buf,
  751. int resp_buf_len)
  752. {
  753. struct be_ctrl_info *ctrl = &phba->ctrl;
  754. struct be_mcc_wrb *wrb;
  755. struct be_sge *sge;
  756. unsigned int tag;
  757. int rc = 0;
  758. spin_lock(&ctrl->mbox_lock);
  759. tag = alloc_mcc_tag(phba);
  760. if (!tag) {
  761. spin_unlock(&ctrl->mbox_lock);
  762. rc = -ENOMEM;
  763. goto free_cmd;
  764. }
  765. wrb = wrb_from_mccq(phba);
  766. wrb->tag0 |= tag;
  767. sge = nonembedded_sgl(wrb);
  768. be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1);
  769. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  770. sge->pa_lo = cpu_to_le32(lower_32_bits(nonemb_cmd->dma));
  771. sge->len = cpu_to_le32(nonemb_cmd->size);
  772. be_mcc_notify(phba);
  773. spin_unlock(&ctrl->mbox_lock);
  774. rc = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd);
  775. if (resp_buf)
  776. memcpy(resp_buf, nonemb_cmd->va, resp_buf_len);
  777. if (rc) {
  778. /* Check if the MBX Cmd needs to be re-issued */
  779. if (rc == -EAGAIN)
  780. return rc;
  781. beiscsi_log(phba, KERN_WARNING,
  782. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  783. "BG_%d : mgmt_exec_nonemb_cmd Failed status\n");
  784. if (rc != -EBUSY)
  785. goto free_cmd;
  786. else
  787. return rc;
  788. }
  789. free_cmd:
  790. pci_free_consistent(ctrl->pdev, nonemb_cmd->size,
  791. nonemb_cmd->va, nonemb_cmd->dma);
  792. return rc;
  793. }
  794. static int mgmt_alloc_cmd_data(struct beiscsi_hba *phba, struct be_dma_mem *cmd,
  795. int iscsi_cmd, int size)
  796. {
  797. cmd->va = pci_zalloc_consistent(phba->ctrl.pdev, size, &cmd->dma);
  798. if (!cmd->va) {
  799. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  800. "BG_%d : Failed to allocate memory for if info\n");
  801. return -ENOMEM;
  802. }
  803. cmd->size = size;
  804. be_cmd_hdr_prepare(cmd->va, CMD_SUBSYSTEM_ISCSI, iscsi_cmd, size);
  805. return 0;
  806. }
  807. static int
  808. mgmt_static_ip_modify(struct beiscsi_hba *phba,
  809. struct be_cmd_get_if_info_resp *if_info,
  810. struct iscsi_iface_param_info *ip_param,
  811. struct iscsi_iface_param_info *subnet_param,
  812. uint32_t ip_action)
  813. {
  814. struct be_cmd_set_ip_addr_req *req;
  815. struct be_dma_mem nonemb_cmd;
  816. uint32_t ip_type;
  817. int rc;
  818. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  819. OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR,
  820. sizeof(*req));
  821. if (rc)
  822. return rc;
  823. ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
  824. BE2_IPV6 : BE2_IPV4 ;
  825. req = nonemb_cmd.va;
  826. req->ip_params.record_entry_count = 1;
  827. req->ip_params.ip_record.action = ip_action;
  828. req->ip_params.ip_record.interface_hndl =
  829. phba->interface_handle;
  830. req->ip_params.ip_record.ip_addr.size_of_structure =
  831. sizeof(struct be_ip_addr_subnet_format);
  832. req->ip_params.ip_record.ip_addr.ip_type = ip_type;
  833. if (ip_action == IP_ACTION_ADD) {
  834. memcpy(req->ip_params.ip_record.ip_addr.addr, ip_param->value,
  835. sizeof(req->ip_params.ip_record.ip_addr.addr));
  836. if (subnet_param)
  837. memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
  838. subnet_param->value,
  839. sizeof(req->ip_params.ip_record.ip_addr.subnet_mask));
  840. } else {
  841. memcpy(req->ip_params.ip_record.ip_addr.addr,
  842. if_info->ip_addr.addr,
  843. sizeof(req->ip_params.ip_record.ip_addr.addr));
  844. memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
  845. if_info->ip_addr.subnet_mask,
  846. sizeof(req->ip_params.ip_record.ip_addr.subnet_mask));
  847. }
  848. rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
  849. if (rc < 0)
  850. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  851. "BG_%d : Failed to Modify existing IP Address\n");
  852. return rc;
  853. }
  854. static int mgmt_modify_gateway(struct beiscsi_hba *phba, uint8_t *gt_addr,
  855. uint32_t gtway_action, uint32_t param_len)
  856. {
  857. struct be_cmd_set_def_gateway_req *req;
  858. struct be_dma_mem nonemb_cmd;
  859. int rt_val;
  860. rt_val = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  861. OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY,
  862. sizeof(*req));
  863. if (rt_val)
  864. return rt_val;
  865. req = nonemb_cmd.va;
  866. req->action = gtway_action;
  867. req->ip_addr.ip_type = BE2_IPV4;
  868. memcpy(req->ip_addr.addr, gt_addr, sizeof(req->ip_addr.addr));
  869. return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
  870. }
  871. int mgmt_set_ip(struct beiscsi_hba *phba,
  872. struct iscsi_iface_param_info *ip_param,
  873. struct iscsi_iface_param_info *subnet_param,
  874. uint32_t boot_proto)
  875. {
  876. struct be_cmd_get_def_gateway_resp gtway_addr_set;
  877. struct be_cmd_get_if_info_resp *if_info;
  878. struct be_cmd_set_dhcp_req *dhcpreq;
  879. struct be_cmd_rel_dhcp_req *reldhcp;
  880. struct be_dma_mem nonemb_cmd;
  881. uint8_t *gtway_addr;
  882. uint32_t ip_type;
  883. int rc;
  884. if (mgmt_get_all_if_id(phba))
  885. return -EIO;
  886. ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
  887. BE2_IPV6 : BE2_IPV4 ;
  888. rc = mgmt_get_if_info(phba, ip_type, &if_info);
  889. if (rc)
  890. return rc;
  891. if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
  892. if (if_info->dhcp_state) {
  893. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  894. "BG_%d : DHCP Already Enabled\n");
  895. goto exit;
  896. }
  897. /* The ip_param->len is 1 in DHCP case. Setting
  898. proper IP len as this it is used while
  899. freeing the Static IP.
  900. */
  901. ip_param->len = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
  902. IP_V6_LEN : IP_V4_LEN;
  903. } else {
  904. if (if_info->dhcp_state) {
  905. memset(if_info, 0, sizeof(*if_info));
  906. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  907. OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR,
  908. sizeof(*reldhcp));
  909. if (rc)
  910. goto exit;
  911. reldhcp = nonemb_cmd.va;
  912. reldhcp->interface_hndl = phba->interface_handle;
  913. reldhcp->ip_type = ip_type;
  914. rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
  915. if (rc < 0) {
  916. beiscsi_log(phba, KERN_WARNING,
  917. BEISCSI_LOG_CONFIG,
  918. "BG_%d : Failed to Delete existing dhcp\n");
  919. goto exit;
  920. }
  921. }
  922. }
  923. /* Delete the Static IP Set */
  924. if (if_info->ip_addr.addr[0]) {
  925. rc = mgmt_static_ip_modify(phba, if_info, ip_param, NULL,
  926. IP_ACTION_DEL);
  927. if (rc)
  928. goto exit;
  929. }
  930. /* Delete the Gateway settings if mode change is to DHCP */
  931. if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
  932. memset(&gtway_addr_set, 0, sizeof(gtway_addr_set));
  933. rc = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set);
  934. if (rc) {
  935. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  936. "BG_%d : Failed to Get Gateway Addr\n");
  937. goto exit;
  938. }
  939. if (gtway_addr_set.ip_addr.addr[0]) {
  940. gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr;
  941. rc = mgmt_modify_gateway(phba, gtway_addr,
  942. IP_ACTION_DEL, IP_V4_LEN);
  943. if (rc) {
  944. beiscsi_log(phba, KERN_WARNING,
  945. BEISCSI_LOG_CONFIG,
  946. "BG_%d : Failed to clear Gateway Addr Set\n");
  947. goto exit;
  948. }
  949. }
  950. }
  951. /* Set Adapter to DHCP/Static Mode */
  952. if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
  953. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  954. OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR,
  955. sizeof(*dhcpreq));
  956. if (rc)
  957. goto exit;
  958. dhcpreq = nonemb_cmd.va;
  959. dhcpreq->flags = BLOCKING;
  960. dhcpreq->retry_count = 1;
  961. dhcpreq->interface_hndl = phba->interface_handle;
  962. dhcpreq->ip_type = BE2_DHCP_V4;
  963. rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
  964. } else {
  965. rc = mgmt_static_ip_modify(phba, if_info, ip_param,
  966. subnet_param, IP_ACTION_ADD);
  967. }
  968. exit:
  969. kfree(if_info);
  970. return rc;
  971. }
  972. int mgmt_set_gateway(struct beiscsi_hba *phba,
  973. struct iscsi_iface_param_info *gateway_param)
  974. {
  975. struct be_cmd_get_def_gateway_resp gtway_addr_set;
  976. uint8_t *gtway_addr;
  977. int rt_val;
  978. memset(&gtway_addr_set, 0, sizeof(gtway_addr_set));
  979. rt_val = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set);
  980. if (rt_val) {
  981. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  982. "BG_%d : Failed to Get Gateway Addr\n");
  983. return rt_val;
  984. }
  985. if (gtway_addr_set.ip_addr.addr[0]) {
  986. gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr;
  987. rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_DEL,
  988. gateway_param->len);
  989. if (rt_val) {
  990. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  991. "BG_%d : Failed to clear Gateway Addr Set\n");
  992. return rt_val;
  993. }
  994. }
  995. gtway_addr = (uint8_t *)&gateway_param->value;
  996. rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_ADD,
  997. gateway_param->len);
  998. if (rt_val)
  999. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  1000. "BG_%d : Failed to Set Gateway Addr\n");
  1001. return rt_val;
  1002. }
  1003. int mgmt_get_gateway(struct beiscsi_hba *phba, int ip_type,
  1004. struct be_cmd_get_def_gateway_resp *gateway)
  1005. {
  1006. struct be_cmd_get_def_gateway_req *req;
  1007. struct be_dma_mem nonemb_cmd;
  1008. int rc;
  1009. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  1010. OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY,
  1011. sizeof(*gateway));
  1012. if (rc)
  1013. return rc;
  1014. req = nonemb_cmd.va;
  1015. req->ip_type = ip_type;
  1016. return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, gateway,
  1017. sizeof(*gateway));
  1018. }
  1019. int mgmt_get_if_info(struct beiscsi_hba *phba, int ip_type,
  1020. struct be_cmd_get_if_info_resp **if_info)
  1021. {
  1022. struct be_cmd_get_if_info_req *req;
  1023. struct be_dma_mem nonemb_cmd;
  1024. uint32_t ioctl_size = sizeof(struct be_cmd_get_if_info_resp);
  1025. int rc;
  1026. if (mgmt_get_all_if_id(phba))
  1027. return -EIO;
  1028. do {
  1029. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  1030. OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO,
  1031. ioctl_size);
  1032. if (rc)
  1033. return rc;
  1034. req = nonemb_cmd.va;
  1035. req->interface_hndl = phba->interface_handle;
  1036. req->ip_type = ip_type;
  1037. /* Allocate memory for if_info */
  1038. *if_info = kzalloc(ioctl_size, GFP_KERNEL);
  1039. if (!*if_info) {
  1040. beiscsi_log(phba, KERN_ERR,
  1041. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  1042. "BG_%d : Memory Allocation Failure\n");
  1043. /* Free the DMA memory for the IOCTL issuing */
  1044. pci_free_consistent(phba->ctrl.pdev,
  1045. nonemb_cmd.size,
  1046. nonemb_cmd.va,
  1047. nonemb_cmd.dma);
  1048. return -ENOMEM;
  1049. }
  1050. rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, *if_info,
  1051. ioctl_size);
  1052. /* Check if the error is because of Insufficent_Buffer */
  1053. if (rc == -EAGAIN) {
  1054. /* Get the new memory size */
  1055. ioctl_size = ((struct be_cmd_resp_hdr *)
  1056. nonemb_cmd.va)->actual_resp_len;
  1057. ioctl_size += sizeof(struct be_cmd_req_hdr);
  1058. /* Free the previous allocated DMA memory */
  1059. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  1060. nonemb_cmd.va,
  1061. nonemb_cmd.dma);
  1062. /* Free the virtual memory */
  1063. kfree(*if_info);
  1064. } else
  1065. break;
  1066. } while (true);
  1067. return rc;
  1068. }
  1069. int mgmt_get_nic_conf(struct beiscsi_hba *phba,
  1070. struct be_cmd_get_nic_conf_resp *nic)
  1071. {
  1072. struct be_dma_mem nonemb_cmd;
  1073. int rc;
  1074. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  1075. OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
  1076. sizeof(*nic));
  1077. if (rc)
  1078. return rc;
  1079. return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, nic, sizeof(*nic));
  1080. }
  1081. unsigned int be_cmd_get_initname(struct beiscsi_hba *phba)
  1082. {
  1083. unsigned int tag = 0;
  1084. struct be_mcc_wrb *wrb;
  1085. struct be_cmd_hba_name *req;
  1086. struct be_ctrl_info *ctrl = &phba->ctrl;
  1087. spin_lock(&ctrl->mbox_lock);
  1088. tag = alloc_mcc_tag(phba);
  1089. if (!tag) {
  1090. spin_unlock(&ctrl->mbox_lock);
  1091. return tag;
  1092. }
  1093. wrb = wrb_from_mccq(phba);
  1094. req = embedded_payload(wrb);
  1095. wrb->tag0 |= tag;
  1096. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1097. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  1098. OPCODE_ISCSI_INI_CFG_GET_HBA_NAME,
  1099. sizeof(*req));
  1100. be_mcc_notify(phba);
  1101. spin_unlock(&ctrl->mbox_lock);
  1102. return tag;
  1103. }
  1104. unsigned int be_cmd_get_port_speed(struct beiscsi_hba *phba)
  1105. {
  1106. unsigned int tag = 0;
  1107. struct be_mcc_wrb *wrb;
  1108. struct be_cmd_ntwk_link_status_req *req;
  1109. struct be_ctrl_info *ctrl = &phba->ctrl;
  1110. spin_lock(&ctrl->mbox_lock);
  1111. tag = alloc_mcc_tag(phba);
  1112. if (!tag) {
  1113. spin_unlock(&ctrl->mbox_lock);
  1114. return tag;
  1115. }
  1116. wrb = wrb_from_mccq(phba);
  1117. req = embedded_payload(wrb);
  1118. wrb->tag0 |= tag;
  1119. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1120. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1121. OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
  1122. sizeof(*req));
  1123. be_mcc_notify(phba);
  1124. spin_unlock(&ctrl->mbox_lock);
  1125. return tag;
  1126. }
  1127. /**
  1128. * be_mgmt_get_boot_shandle()- Get the session handle
  1129. * @phba: device priv structure instance
  1130. * @s_handle: session handle returned for boot session.
  1131. *
  1132. * Get the boot target session handle. In case of
  1133. * crashdump mode driver has to issue and MBX Cmd
  1134. * for FW to login to boot target
  1135. *
  1136. * return
  1137. * Success: 0
  1138. * Failure: Non-Zero value
  1139. *
  1140. **/
  1141. int be_mgmt_get_boot_shandle(struct beiscsi_hba *phba,
  1142. unsigned int *s_handle)
  1143. {
  1144. struct be_cmd_get_boot_target_resp *boot_resp;
  1145. struct be_mcc_wrb *wrb;
  1146. unsigned int tag;
  1147. uint8_t boot_retry = 3;
  1148. int rc;
  1149. do {
  1150. /* Get the Boot Target Session Handle and Count*/
  1151. tag = mgmt_get_boot_target(phba);
  1152. if (!tag) {
  1153. beiscsi_log(phba, KERN_ERR,
  1154. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  1155. "BG_%d : Getting Boot Target Info Failed\n");
  1156. return -EAGAIN;
  1157. }
  1158. rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
  1159. if (rc) {
  1160. beiscsi_log(phba, KERN_ERR,
  1161. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  1162. "BG_%d : MBX CMD get_boot_target Failed\n");
  1163. return -EBUSY;
  1164. }
  1165. boot_resp = embedded_payload(wrb);
  1166. /* Check if the there are any Boot targets configured */
  1167. if (!boot_resp->boot_session_count) {
  1168. beiscsi_log(phba, KERN_INFO,
  1169. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  1170. "BG_%d ;No boot targets configured\n");
  1171. return -ENXIO;
  1172. }
  1173. /* FW returns the session handle of the boot session */
  1174. if (boot_resp->boot_session_handle != INVALID_SESS_HANDLE) {
  1175. *s_handle = boot_resp->boot_session_handle;
  1176. return 0;
  1177. }
  1178. /* Issue MBX Cmd to FW to login to the boot target */
  1179. tag = mgmt_reopen_session(phba, BE_REOPEN_BOOT_SESSIONS,
  1180. INVALID_SESS_HANDLE);
  1181. if (!tag) {
  1182. beiscsi_log(phba, KERN_ERR,
  1183. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  1184. "BG_%d : mgmt_reopen_session Failed\n");
  1185. return -EAGAIN;
  1186. }
  1187. rc = beiscsi_mccq_compl(phba, tag, NULL, NULL);
  1188. if (rc) {
  1189. beiscsi_log(phba, KERN_ERR,
  1190. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  1191. "BG_%d : mgmt_reopen_session Failed");
  1192. return rc;
  1193. }
  1194. } while (--boot_retry);
  1195. /* Couldn't log into the boot target */
  1196. beiscsi_log(phba, KERN_ERR,
  1197. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  1198. "BG_%d : Login to Boot Target Failed\n");
  1199. return -ENXIO;
  1200. }
  1201. /**
  1202. * mgmt_set_vlan()- Issue and wait for CMD completion
  1203. * @phba: device private structure instance
  1204. * @vlan_tag: VLAN tag
  1205. *
  1206. * Issue the MBX Cmd and wait for the completion of the
  1207. * command.
  1208. *
  1209. * returns
  1210. * Success: 0
  1211. * Failure: Non-Xero Value
  1212. **/
  1213. int mgmt_set_vlan(struct beiscsi_hba *phba,
  1214. uint16_t vlan_tag)
  1215. {
  1216. int rc;
  1217. unsigned int tag;
  1218. tag = be_cmd_set_vlan(phba, vlan_tag);
  1219. if (!tag) {
  1220. beiscsi_log(phba, KERN_ERR,
  1221. (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
  1222. "BG_%d : VLAN Setting Failed\n");
  1223. return -EBUSY;
  1224. }
  1225. rc = beiscsi_mccq_compl(phba, tag, NULL, NULL);
  1226. if (rc) {
  1227. beiscsi_log(phba, KERN_ERR,
  1228. (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
  1229. "BS_%d : VLAN MBX Cmd Failed\n");
  1230. return rc;
  1231. }
  1232. return rc;
  1233. }
  1234. /**
  1235. * beiscsi_drvr_ver_disp()- Display the driver Name and Version
  1236. * @dev: ptr to device not used.
  1237. * @attr: device attribute, not used.
  1238. * @buf: contains formatted text driver name and version
  1239. *
  1240. * return
  1241. * size of the formatted string
  1242. **/
  1243. ssize_t
  1244. beiscsi_drvr_ver_disp(struct device *dev, struct device_attribute *attr,
  1245. char *buf)
  1246. {
  1247. return snprintf(buf, PAGE_SIZE, BE_NAME "\n");
  1248. }
  1249. /**
  1250. * beiscsi_fw_ver_disp()- Display Firmware Version
  1251. * @dev: ptr to device not used.
  1252. * @attr: device attribute, not used.
  1253. * @buf: contains formatted text Firmware version
  1254. *
  1255. * return
  1256. * size of the formatted string
  1257. **/
  1258. ssize_t
  1259. beiscsi_fw_ver_disp(struct device *dev, struct device_attribute *attr,
  1260. char *buf)
  1261. {
  1262. struct Scsi_Host *shost = class_to_shost(dev);
  1263. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  1264. return snprintf(buf, PAGE_SIZE, "%s\n", phba->fw_ver_str);
  1265. }
  1266. /**
  1267. * beiscsi_active_session_disp()- Display Sessions Active
  1268. * @dev: ptr to device not used.
  1269. * @attr: device attribute, not used.
  1270. * @buf: contains formatted text Session Count
  1271. *
  1272. * return
  1273. * size of the formatted string
  1274. **/
  1275. ssize_t
  1276. beiscsi_active_session_disp(struct device *dev, struct device_attribute *attr,
  1277. char *buf)
  1278. {
  1279. struct Scsi_Host *shost = class_to_shost(dev);
  1280. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  1281. uint16_t avlbl_cids = 0, ulp_num, len = 0, total_cids = 0;
  1282. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  1283. if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
  1284. avlbl_cids = BEISCSI_ULP_AVLBL_CID(phba, ulp_num);
  1285. total_cids = BEISCSI_GET_CID_COUNT(phba, ulp_num);
  1286. len += snprintf(buf+len, PAGE_SIZE - len,
  1287. "ULP%d : %d\n", ulp_num,
  1288. (total_cids - avlbl_cids));
  1289. } else
  1290. len += snprintf(buf+len, PAGE_SIZE - len,
  1291. "ULP%d : %d\n", ulp_num, 0);
  1292. }
  1293. return len;
  1294. }
  1295. /**
  1296. * beiscsi_free_session_disp()- Display Avaliable Session
  1297. * @dev: ptr to device not used.
  1298. * @attr: device attribute, not used.
  1299. * @buf: contains formatted text Session Count
  1300. *
  1301. * return
  1302. * size of the formatted string
  1303. **/
  1304. ssize_t
  1305. beiscsi_free_session_disp(struct device *dev, struct device_attribute *attr,
  1306. char *buf)
  1307. {
  1308. struct Scsi_Host *shost = class_to_shost(dev);
  1309. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  1310. uint16_t ulp_num, len = 0;
  1311. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  1312. if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported))
  1313. len += snprintf(buf+len, PAGE_SIZE - len,
  1314. "ULP%d : %d\n", ulp_num,
  1315. BEISCSI_ULP_AVLBL_CID(phba, ulp_num));
  1316. else
  1317. len += snprintf(buf+len, PAGE_SIZE - len,
  1318. "ULP%d : %d\n", ulp_num, 0);
  1319. }
  1320. return len;
  1321. }
  1322. /**
  1323. * beiscsi_adap_family_disp()- Display adapter family.
  1324. * @dev: ptr to device to get priv structure
  1325. * @attr: device attribute, not used.
  1326. * @buf: contains formatted text driver name and version
  1327. *
  1328. * return
  1329. * size of the formatted string
  1330. **/
  1331. ssize_t
  1332. beiscsi_adap_family_disp(struct device *dev, struct device_attribute *attr,
  1333. char *buf)
  1334. {
  1335. uint16_t dev_id = 0;
  1336. struct Scsi_Host *shost = class_to_shost(dev);
  1337. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  1338. dev_id = phba->pcidev->device;
  1339. switch (dev_id) {
  1340. case BE_DEVICE_ID1:
  1341. case OC_DEVICE_ID1:
  1342. case OC_DEVICE_ID2:
  1343. return snprintf(buf, PAGE_SIZE, "BE2 Adapter Family\n");
  1344. break;
  1345. case BE_DEVICE_ID2:
  1346. case OC_DEVICE_ID3:
  1347. return snprintf(buf, PAGE_SIZE, "BE3-R Adapter Family\n");
  1348. break;
  1349. case OC_SKH_ID1:
  1350. return snprintf(buf, PAGE_SIZE, "Skyhawk-R Adapter Family\n");
  1351. break;
  1352. default:
  1353. return snprintf(buf, PAGE_SIZE,
  1354. "Unknown Adapter Family: 0x%x\n", dev_id);
  1355. break;
  1356. }
  1357. }
  1358. /**
  1359. * beiscsi_phys_port()- Display Physical Port Identifier
  1360. * @dev: ptr to device not used.
  1361. * @attr: device attribute, not used.
  1362. * @buf: contains formatted text port identifier
  1363. *
  1364. * return
  1365. * size of the formatted string
  1366. **/
  1367. ssize_t
  1368. beiscsi_phys_port_disp(struct device *dev, struct device_attribute *attr,
  1369. char *buf)
  1370. {
  1371. struct Scsi_Host *shost = class_to_shost(dev);
  1372. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  1373. return snprintf(buf, PAGE_SIZE, "Port Identifier : %d\n",
  1374. phba->fw_config.phys_port);
  1375. }
  1376. void beiscsi_offload_cxn_v0(struct beiscsi_offload_params *params,
  1377. struct wrb_handle *pwrb_handle,
  1378. struct be_mem_descriptor *mem_descr)
  1379. {
  1380. struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
  1381. memset(pwrb, 0, sizeof(*pwrb));
  1382. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  1383. max_send_data_segment_length, pwrb,
  1384. params->dw[offsetof(struct amap_beiscsi_offload_params,
  1385. max_send_data_segment_length) / 32]);
  1386. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
  1387. BE_TGT_CTX_UPDT_CMD);
  1388. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  1389. first_burst_length,
  1390. pwrb,
  1391. params->dw[offsetof(struct amap_beiscsi_offload_params,
  1392. first_burst_length) / 32]);
  1393. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
  1394. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1395. erl) / 32] & OFFLD_PARAMS_ERL));
  1396. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
  1397. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1398. dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
  1399. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
  1400. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1401. hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
  1402. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
  1403. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1404. ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
  1405. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
  1406. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1407. imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
  1408. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
  1409. pwrb,
  1410. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1411. exp_statsn) / 32] + 1));
  1412. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
  1413. pwrb, pwrb_handle->wrb_index);
  1414. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  1415. max_burst_length, pwrb, params->dw[offsetof
  1416. (struct amap_beiscsi_offload_params,
  1417. max_burst_length) / 32]);
  1418. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
  1419. pwrb, pwrb_handle->nxt_wrb_index);
  1420. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  1421. session_state, pwrb, 0);
  1422. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
  1423. pwrb, 1);
  1424. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
  1425. pwrb, 0);
  1426. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
  1427. 0);
  1428. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  1429. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  1430. pad_buffer_addr_hi, pwrb,
  1431. mem_descr->mem_array[0].bus_address.u.a32.address_hi);
  1432. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  1433. pad_buffer_addr_lo, pwrb,
  1434. mem_descr->mem_array[0].bus_address.u.a32.address_lo);
  1435. }
  1436. void beiscsi_offload_cxn_v2(struct beiscsi_offload_params *params,
  1437. struct wrb_handle *pwrb_handle)
  1438. {
  1439. struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
  1440. memset(pwrb, 0, sizeof(*pwrb));
  1441. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1442. max_burst_length, pwrb, params->dw[offsetof
  1443. (struct amap_beiscsi_offload_params,
  1444. max_burst_length) / 32]);
  1445. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1446. type, pwrb,
  1447. BE_TGT_CTX_UPDT_CMD);
  1448. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1449. ptr2nextwrb,
  1450. pwrb, pwrb_handle->nxt_wrb_index);
  1451. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, wrb_idx,
  1452. pwrb, pwrb_handle->wrb_index);
  1453. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1454. max_send_data_segment_length, pwrb,
  1455. params->dw[offsetof(struct amap_beiscsi_offload_params,
  1456. max_send_data_segment_length) / 32]);
  1457. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1458. first_burst_length, pwrb,
  1459. params->dw[offsetof(struct amap_beiscsi_offload_params,
  1460. first_burst_length) / 32]);
  1461. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1462. max_recv_dataseg_len, pwrb,
  1463. params->dw[offsetof(struct amap_beiscsi_offload_params,
  1464. max_recv_data_segment_length) / 32]);
  1465. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1466. max_cxns, pwrb, BEISCSI_MAX_CXNS);
  1467. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, erl, pwrb,
  1468. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1469. erl) / 32] & OFFLD_PARAMS_ERL));
  1470. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, dde, pwrb,
  1471. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1472. dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
  1473. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, hde, pwrb,
  1474. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1475. hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
  1476. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1477. ir2t, pwrb,
  1478. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1479. ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
  1480. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, imd, pwrb,
  1481. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1482. imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
  1483. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1484. data_seq_inorder,
  1485. pwrb,
  1486. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1487. data_seq_inorder) / 32] &
  1488. OFFLD_PARAMS_DATA_SEQ_INORDER) >> 6);
  1489. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
  1490. pdu_seq_inorder,
  1491. pwrb,
  1492. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1493. pdu_seq_inorder) / 32] &
  1494. OFFLD_PARAMS_PDU_SEQ_INORDER) >> 7);
  1495. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, max_r2t,
  1496. pwrb,
  1497. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1498. max_r2t) / 32] &
  1499. OFFLD_PARAMS_MAX_R2T) >> 8);
  1500. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, stat_sn,
  1501. pwrb,
  1502. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  1503. exp_statsn) / 32] + 1));
  1504. }
  1505. /**
  1506. * beiscsi_logout_fw_sess()- Firmware Session Logout
  1507. * @phba: Device priv structure instance
  1508. * @fw_sess_handle: FW session handle
  1509. *
  1510. * Logout from the FW established sessions.
  1511. * returns
  1512. * Success: 0
  1513. * Failure: Non-Zero Value
  1514. *
  1515. */
  1516. int beiscsi_logout_fw_sess(struct beiscsi_hba *phba,
  1517. uint32_t fw_sess_handle)
  1518. {
  1519. struct be_ctrl_info *ctrl = &phba->ctrl;
  1520. struct be_mcc_wrb *wrb;
  1521. struct be_cmd_req_logout_fw_sess *req;
  1522. struct be_cmd_resp_logout_fw_sess *resp;
  1523. unsigned int tag;
  1524. int rc;
  1525. beiscsi_log(phba, KERN_INFO,
  1526. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  1527. "BG_%d : In bescsi_logout_fwboot_sess\n");
  1528. spin_lock(&ctrl->mbox_lock);
  1529. tag = alloc_mcc_tag(phba);
  1530. if (!tag) {
  1531. spin_unlock(&ctrl->mbox_lock);
  1532. beiscsi_log(phba, KERN_INFO,
  1533. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  1534. "BG_%d : MBX Tag Failure\n");
  1535. return -EINVAL;
  1536. }
  1537. wrb = wrb_from_mccq(phba);
  1538. req = embedded_payload(wrb);
  1539. wrb->tag0 |= tag;
  1540. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1541. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  1542. OPCODE_ISCSI_INI_SESSION_LOGOUT_TARGET,
  1543. sizeof(struct be_cmd_req_logout_fw_sess));
  1544. /* Set the session handle */
  1545. req->session_handle = fw_sess_handle;
  1546. be_mcc_notify(phba);
  1547. spin_unlock(&ctrl->mbox_lock);
  1548. rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
  1549. if (rc) {
  1550. beiscsi_log(phba, KERN_ERR,
  1551. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  1552. "BG_%d : MBX CMD FW_SESSION_LOGOUT_TARGET Failed\n");
  1553. return -EBUSY;
  1554. }
  1555. resp = embedded_payload(wrb);
  1556. if (resp->session_status !=
  1557. BEISCSI_MGMT_SESSION_CLOSE) {
  1558. beiscsi_log(phba, KERN_ERR,
  1559. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  1560. "BG_%d : FW_SESSION_LOGOUT_TARGET resp : 0x%x\n",
  1561. resp->session_status);
  1562. rc = -EINVAL;
  1563. }
  1564. return rc;
  1565. }