qla_attr.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_target.h"
  9. #include <linux/kthread.h>
  10. #include <linux/vmalloc.h>
  11. #include <linux/slab.h>
  12. #include <linux/delay.h>
  13. static int qla24xx_vport_disable(struct fc_vport *, bool);
  14. /* SYSFS attributes --------------------------------------------------------- */
  15. static ssize_t
  16. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  17. struct bin_attribute *bin_attr,
  18. char *buf, loff_t off, size_t count)
  19. {
  20. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  21. struct device, kobj)));
  22. struct qla_hw_data *ha = vha->hw;
  23. int rval = 0;
  24. if (!(ha->fw_dump_reading || ha->mctp_dump_reading))
  25. return 0;
  26. if (IS_P3P_TYPE(ha)) {
  27. if (off < ha->md_template_size) {
  28. rval = memory_read_from_buffer(buf, count,
  29. &off, ha->md_tmplt_hdr, ha->md_template_size);
  30. return rval;
  31. }
  32. off -= ha->md_template_size;
  33. rval = memory_read_from_buffer(buf, count,
  34. &off, ha->md_dump, ha->md_dump_size);
  35. return rval;
  36. } else if (ha->mctp_dumped && ha->mctp_dump_reading)
  37. return memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
  38. MCTP_DUMP_SIZE);
  39. else if (ha->fw_dump_reading)
  40. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  41. ha->fw_dump_len);
  42. else
  43. return 0;
  44. }
  45. static ssize_t
  46. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  47. struct bin_attribute *bin_attr,
  48. char *buf, loff_t off, size_t count)
  49. {
  50. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  51. struct device, kobj)));
  52. struct qla_hw_data *ha = vha->hw;
  53. int reading;
  54. if (off != 0)
  55. return (0);
  56. reading = simple_strtol(buf, NULL, 10);
  57. switch (reading) {
  58. case 0:
  59. if (!ha->fw_dump_reading)
  60. break;
  61. ql_log(ql_log_info, vha, 0x705d,
  62. "Firmware dump cleared on (%ld).\n", vha->host_no);
  63. if (IS_P3P_TYPE(ha)) {
  64. qla82xx_md_free(vha);
  65. qla82xx_md_prep(vha);
  66. }
  67. ha->fw_dump_reading = 0;
  68. ha->fw_dumped = 0;
  69. break;
  70. case 1:
  71. if (ha->fw_dumped && !ha->fw_dump_reading) {
  72. ha->fw_dump_reading = 1;
  73. ql_log(ql_log_info, vha, 0x705e,
  74. "Raw firmware dump ready for read on (%ld).\n",
  75. vha->host_no);
  76. }
  77. break;
  78. case 2:
  79. qla2x00_alloc_fw_dump(vha);
  80. break;
  81. case 3:
  82. if (IS_QLA82XX(ha)) {
  83. qla82xx_idc_lock(ha);
  84. qla82xx_set_reset_owner(vha);
  85. qla82xx_idc_unlock(ha);
  86. } else if (IS_QLA8044(ha)) {
  87. qla8044_idc_lock(ha);
  88. qla82xx_set_reset_owner(vha);
  89. qla8044_idc_unlock(ha);
  90. } else
  91. qla2x00_system_error(vha);
  92. break;
  93. case 4:
  94. if (IS_P3P_TYPE(ha)) {
  95. if (ha->md_tmplt_hdr)
  96. ql_dbg(ql_dbg_user, vha, 0x705b,
  97. "MiniDump supported with this firmware.\n");
  98. else
  99. ql_dbg(ql_dbg_user, vha, 0x709d,
  100. "MiniDump not supported with this firmware.\n");
  101. }
  102. break;
  103. case 5:
  104. if (IS_P3P_TYPE(ha))
  105. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  106. break;
  107. case 6:
  108. if (!ha->mctp_dump_reading)
  109. break;
  110. ql_log(ql_log_info, vha, 0x70c1,
  111. "MCTP dump cleared on (%ld).\n", vha->host_no);
  112. ha->mctp_dump_reading = 0;
  113. ha->mctp_dumped = 0;
  114. break;
  115. case 7:
  116. if (ha->mctp_dumped && !ha->mctp_dump_reading) {
  117. ha->mctp_dump_reading = 1;
  118. ql_log(ql_log_info, vha, 0x70c2,
  119. "Raw mctp dump ready for read on (%ld).\n",
  120. vha->host_no);
  121. }
  122. break;
  123. }
  124. return count;
  125. }
  126. static struct bin_attribute sysfs_fw_dump_attr = {
  127. .attr = {
  128. .name = "fw_dump",
  129. .mode = S_IRUSR | S_IWUSR,
  130. },
  131. .size = 0,
  132. .read = qla2x00_sysfs_read_fw_dump,
  133. .write = qla2x00_sysfs_write_fw_dump,
  134. };
  135. static ssize_t
  136. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  137. struct bin_attribute *bin_attr,
  138. char *buf, loff_t off, size_t count)
  139. {
  140. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  141. struct device, kobj)));
  142. struct qla_hw_data *ha = vha->hw;
  143. if (!capable(CAP_SYS_ADMIN))
  144. return 0;
  145. if (IS_NOCACHE_VPD_TYPE(ha))
  146. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  147. ha->nvram_size);
  148. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  149. ha->nvram_size);
  150. }
  151. static ssize_t
  152. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  153. struct bin_attribute *bin_attr,
  154. char *buf, loff_t off, size_t count)
  155. {
  156. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  157. struct device, kobj)));
  158. struct qla_hw_data *ha = vha->hw;
  159. uint16_t cnt;
  160. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  161. !ha->isp_ops->write_nvram)
  162. return -EINVAL;
  163. /* Checksum NVRAM. */
  164. if (IS_FWI2_CAPABLE(ha)) {
  165. uint32_t *iter;
  166. uint32_t chksum;
  167. iter = (uint32_t *)buf;
  168. chksum = 0;
  169. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  170. chksum += le32_to_cpu(*iter++);
  171. chksum = ~chksum + 1;
  172. *iter = cpu_to_le32(chksum);
  173. } else {
  174. uint8_t *iter;
  175. uint8_t chksum;
  176. iter = (uint8_t *)buf;
  177. chksum = 0;
  178. for (cnt = 0; cnt < count - 1; cnt++)
  179. chksum += *iter++;
  180. chksum = ~chksum + 1;
  181. *iter = chksum;
  182. }
  183. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  184. ql_log(ql_log_warn, vha, 0x705f,
  185. "HBA not online, failing NVRAM update.\n");
  186. return -EAGAIN;
  187. }
  188. /* Write NVRAM. */
  189. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  190. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  191. count);
  192. ql_dbg(ql_dbg_user, vha, 0x7060,
  193. "Setting ISP_ABORT_NEEDED\n");
  194. /* NVRAM settings take effect immediately. */
  195. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  196. qla2xxx_wake_dpc(vha);
  197. qla2x00_wait_for_chip_reset(vha);
  198. return count;
  199. }
  200. static struct bin_attribute sysfs_nvram_attr = {
  201. .attr = {
  202. .name = "nvram",
  203. .mode = S_IRUSR | S_IWUSR,
  204. },
  205. .size = 512,
  206. .read = qla2x00_sysfs_read_nvram,
  207. .write = qla2x00_sysfs_write_nvram,
  208. };
  209. static ssize_t
  210. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  211. struct bin_attribute *bin_attr,
  212. char *buf, loff_t off, size_t count)
  213. {
  214. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  215. struct device, kobj)));
  216. struct qla_hw_data *ha = vha->hw;
  217. if (ha->optrom_state != QLA_SREADING)
  218. return 0;
  219. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  220. ha->optrom_region_size);
  221. }
  222. static ssize_t
  223. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  224. struct bin_attribute *bin_attr,
  225. char *buf, loff_t off, size_t count)
  226. {
  227. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  228. struct device, kobj)));
  229. struct qla_hw_data *ha = vha->hw;
  230. if (ha->optrom_state != QLA_SWRITING)
  231. return -EINVAL;
  232. if (off > ha->optrom_region_size)
  233. return -ERANGE;
  234. if (off + count > ha->optrom_region_size)
  235. count = ha->optrom_region_size - off;
  236. memcpy(&ha->optrom_buffer[off], buf, count);
  237. return count;
  238. }
  239. static struct bin_attribute sysfs_optrom_attr = {
  240. .attr = {
  241. .name = "optrom",
  242. .mode = S_IRUSR | S_IWUSR,
  243. },
  244. .size = 0,
  245. .read = qla2x00_sysfs_read_optrom,
  246. .write = qla2x00_sysfs_write_optrom,
  247. };
  248. static ssize_t
  249. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  250. struct bin_attribute *bin_attr,
  251. char *buf, loff_t off, size_t count)
  252. {
  253. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  254. struct device, kobj)));
  255. struct qla_hw_data *ha = vha->hw;
  256. uint32_t start = 0;
  257. uint32_t size = ha->optrom_size;
  258. int val, valid;
  259. if (off)
  260. return -EINVAL;
  261. if (unlikely(pci_channel_offline(ha->pdev)))
  262. return -EAGAIN;
  263. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  264. return -EINVAL;
  265. if (start > ha->optrom_size)
  266. return -EINVAL;
  267. switch (val) {
  268. case 0:
  269. if (ha->optrom_state != QLA_SREADING &&
  270. ha->optrom_state != QLA_SWRITING)
  271. return -EINVAL;
  272. ha->optrom_state = QLA_SWAITING;
  273. ql_dbg(ql_dbg_user, vha, 0x7061,
  274. "Freeing flash region allocation -- 0x%x bytes.\n",
  275. ha->optrom_region_size);
  276. vfree(ha->optrom_buffer);
  277. ha->optrom_buffer = NULL;
  278. break;
  279. case 1:
  280. if (ha->optrom_state != QLA_SWAITING)
  281. return -EINVAL;
  282. ha->optrom_region_start = start;
  283. ha->optrom_region_size = start + size > ha->optrom_size ?
  284. ha->optrom_size - start : size;
  285. ha->optrom_state = QLA_SREADING;
  286. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  287. if (ha->optrom_buffer == NULL) {
  288. ql_log(ql_log_warn, vha, 0x7062,
  289. "Unable to allocate memory for optrom retrieval "
  290. "(%x).\n", ha->optrom_region_size);
  291. ha->optrom_state = QLA_SWAITING;
  292. return -ENOMEM;
  293. }
  294. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  295. ql_log(ql_log_warn, vha, 0x7063,
  296. "HBA not online, failing NVRAM update.\n");
  297. return -EAGAIN;
  298. }
  299. ql_dbg(ql_dbg_user, vha, 0x7064,
  300. "Reading flash region -- 0x%x/0x%x.\n",
  301. ha->optrom_region_start, ha->optrom_region_size);
  302. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  303. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  304. ha->optrom_region_start, ha->optrom_region_size);
  305. break;
  306. case 2:
  307. if (ha->optrom_state != QLA_SWAITING)
  308. return -EINVAL;
  309. /*
  310. * We need to be more restrictive on which FLASH regions are
  311. * allowed to be updated via user-space. Regions accessible
  312. * via this method include:
  313. *
  314. * ISP21xx/ISP22xx/ISP23xx type boards:
  315. *
  316. * 0x000000 -> 0x020000 -- Boot code.
  317. *
  318. * ISP2322/ISP24xx type boards:
  319. *
  320. * 0x000000 -> 0x07ffff -- Boot code.
  321. * 0x080000 -> 0x0fffff -- Firmware.
  322. *
  323. * ISP25xx type boards:
  324. *
  325. * 0x000000 -> 0x07ffff -- Boot code.
  326. * 0x080000 -> 0x0fffff -- Firmware.
  327. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  328. */
  329. valid = 0;
  330. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  331. valid = 1;
  332. else if (start == (ha->flt_region_boot * 4) ||
  333. start == (ha->flt_region_fw * 4))
  334. valid = 1;
  335. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
  336. || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
  337. valid = 1;
  338. if (!valid) {
  339. ql_log(ql_log_warn, vha, 0x7065,
  340. "Invalid start region 0x%x/0x%x.\n", start, size);
  341. return -EINVAL;
  342. }
  343. ha->optrom_region_start = start;
  344. ha->optrom_region_size = start + size > ha->optrom_size ?
  345. ha->optrom_size - start : size;
  346. ha->optrom_state = QLA_SWRITING;
  347. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  348. if (ha->optrom_buffer == NULL) {
  349. ql_log(ql_log_warn, vha, 0x7066,
  350. "Unable to allocate memory for optrom update "
  351. "(%x)\n", ha->optrom_region_size);
  352. ha->optrom_state = QLA_SWAITING;
  353. return -ENOMEM;
  354. }
  355. ql_dbg(ql_dbg_user, vha, 0x7067,
  356. "Staging flash region write -- 0x%x/0x%x.\n",
  357. ha->optrom_region_start, ha->optrom_region_size);
  358. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  359. break;
  360. case 3:
  361. if (ha->optrom_state != QLA_SWRITING)
  362. return -EINVAL;
  363. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  364. ql_log(ql_log_warn, vha, 0x7068,
  365. "HBA not online, failing flash update.\n");
  366. return -EAGAIN;
  367. }
  368. ql_dbg(ql_dbg_user, vha, 0x7069,
  369. "Writing flash region -- 0x%x/0x%x.\n",
  370. ha->optrom_region_start, ha->optrom_region_size);
  371. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  372. ha->optrom_region_start, ha->optrom_region_size);
  373. break;
  374. default:
  375. return -EINVAL;
  376. }
  377. return count;
  378. }
  379. static struct bin_attribute sysfs_optrom_ctl_attr = {
  380. .attr = {
  381. .name = "optrom_ctl",
  382. .mode = S_IWUSR,
  383. },
  384. .size = 0,
  385. .write = qla2x00_sysfs_write_optrom_ctl,
  386. };
  387. static ssize_t
  388. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  389. struct bin_attribute *bin_attr,
  390. char *buf, loff_t off, size_t count)
  391. {
  392. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  393. struct device, kobj)));
  394. struct qla_hw_data *ha = vha->hw;
  395. if (unlikely(pci_channel_offline(ha->pdev)))
  396. return -EAGAIN;
  397. if (!capable(CAP_SYS_ADMIN))
  398. return -EINVAL;
  399. if (IS_NOCACHE_VPD_TYPE(ha))
  400. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  401. ha->vpd_size);
  402. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  403. }
  404. static ssize_t
  405. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  406. struct bin_attribute *bin_attr,
  407. char *buf, loff_t off, size_t count)
  408. {
  409. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  410. struct device, kobj)));
  411. struct qla_hw_data *ha = vha->hw;
  412. uint8_t *tmp_data;
  413. if (unlikely(pci_channel_offline(ha->pdev)))
  414. return 0;
  415. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  416. !ha->isp_ops->write_nvram)
  417. return 0;
  418. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  419. ql_log(ql_log_warn, vha, 0x706a,
  420. "HBA not online, failing VPD update.\n");
  421. return -EAGAIN;
  422. }
  423. /* Write NVRAM. */
  424. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  425. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  426. /* Update flash version information for 4Gb & above. */
  427. if (!IS_FWI2_CAPABLE(ha))
  428. return -EINVAL;
  429. tmp_data = vmalloc(256);
  430. if (!tmp_data) {
  431. ql_log(ql_log_warn, vha, 0x706b,
  432. "Unable to allocate memory for VPD information update.\n");
  433. return -ENOMEM;
  434. }
  435. ha->isp_ops->get_flash_version(vha, tmp_data);
  436. vfree(tmp_data);
  437. return count;
  438. }
  439. static struct bin_attribute sysfs_vpd_attr = {
  440. .attr = {
  441. .name = "vpd",
  442. .mode = S_IRUSR | S_IWUSR,
  443. },
  444. .size = 0,
  445. .read = qla2x00_sysfs_read_vpd,
  446. .write = qla2x00_sysfs_write_vpd,
  447. };
  448. static ssize_t
  449. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  450. struct bin_attribute *bin_attr,
  451. char *buf, loff_t off, size_t count)
  452. {
  453. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  454. struct device, kobj)));
  455. struct qla_hw_data *ha = vha->hw;
  456. uint16_t iter, addr, offset;
  457. int rval;
  458. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  459. return 0;
  460. if (ha->sfp_data)
  461. goto do_read;
  462. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  463. &ha->sfp_data_dma);
  464. if (!ha->sfp_data) {
  465. ql_log(ql_log_warn, vha, 0x706c,
  466. "Unable to allocate memory for SFP read-data.\n");
  467. return 0;
  468. }
  469. do_read:
  470. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  471. addr = 0xa0;
  472. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  473. iter++, offset += SFP_BLOCK_SIZE) {
  474. if (iter == 4) {
  475. /* Skip to next device address. */
  476. addr = 0xa2;
  477. offset = 0;
  478. }
  479. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
  480. addr, offset, SFP_BLOCK_SIZE, 0);
  481. if (rval != QLA_SUCCESS) {
  482. ql_log(ql_log_warn, vha, 0x706d,
  483. "Unable to read SFP data (%x/%x/%x).\n", rval,
  484. addr, offset);
  485. return -EIO;
  486. }
  487. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  488. buf += SFP_BLOCK_SIZE;
  489. }
  490. return count;
  491. }
  492. static struct bin_attribute sysfs_sfp_attr = {
  493. .attr = {
  494. .name = "sfp",
  495. .mode = S_IRUSR | S_IWUSR,
  496. },
  497. .size = SFP_DEV_SIZE * 2,
  498. .read = qla2x00_sysfs_read_sfp,
  499. };
  500. static ssize_t
  501. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  502. struct bin_attribute *bin_attr,
  503. char *buf, loff_t off, size_t count)
  504. {
  505. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  506. struct device, kobj)));
  507. struct qla_hw_data *ha = vha->hw;
  508. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  509. int type;
  510. uint32_t idc_control;
  511. if (off != 0)
  512. return -EINVAL;
  513. type = simple_strtol(buf, NULL, 10);
  514. switch (type) {
  515. case 0x2025c:
  516. ql_log(ql_log_info, vha, 0x706e,
  517. "Issuing ISP reset.\n");
  518. scsi_block_requests(vha->host);
  519. if (IS_QLA82XX(ha)) {
  520. ha->flags.isp82xx_no_md_cap = 1;
  521. qla82xx_idc_lock(ha);
  522. qla82xx_set_reset_owner(vha);
  523. qla82xx_idc_unlock(ha);
  524. } else if (IS_QLA8044(ha)) {
  525. qla8044_idc_lock(ha);
  526. idc_control = qla8044_rd_reg(ha,
  527. QLA8044_IDC_DRV_CTRL);
  528. qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
  529. (idc_control | GRACEFUL_RESET_BIT1));
  530. qla82xx_set_reset_owner(vha);
  531. qla8044_idc_unlock(ha);
  532. } else {
  533. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  534. qla2xxx_wake_dpc(vha);
  535. }
  536. qla2x00_wait_for_chip_reset(vha);
  537. scsi_unblock_requests(vha->host);
  538. break;
  539. case 0x2025d:
  540. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  541. return -EPERM;
  542. ql_log(ql_log_info, vha, 0x706f,
  543. "Issuing MPI reset.\n");
  544. if (IS_QLA83XX(ha)) {
  545. uint32_t idc_control;
  546. qla83xx_idc_lock(vha, 0);
  547. __qla83xx_get_idc_control(vha, &idc_control);
  548. idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
  549. __qla83xx_set_idc_control(vha, idc_control);
  550. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  551. QLA8XXX_DEV_NEED_RESET);
  552. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  553. qla83xx_idc_unlock(vha, 0);
  554. break;
  555. } else {
  556. /* Make sure FC side is not in reset */
  557. qla2x00_wait_for_hba_online(vha);
  558. /* Issue MPI reset */
  559. scsi_block_requests(vha->host);
  560. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  561. ql_log(ql_log_warn, vha, 0x7070,
  562. "MPI reset failed.\n");
  563. scsi_unblock_requests(vha->host);
  564. break;
  565. }
  566. case 0x2025e:
  567. if (!IS_P3P_TYPE(ha) || vha != base_vha) {
  568. ql_log(ql_log_info, vha, 0x7071,
  569. "FCoE ctx reset no supported.\n");
  570. return -EPERM;
  571. }
  572. ql_log(ql_log_info, vha, 0x7072,
  573. "Issuing FCoE ctx reset.\n");
  574. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  575. qla2xxx_wake_dpc(vha);
  576. qla2x00_wait_for_fcoe_ctx_reset(vha);
  577. break;
  578. case 0x2025f:
  579. if (!IS_QLA8031(ha))
  580. return -EPERM;
  581. ql_log(ql_log_info, vha, 0x70bc,
  582. "Disabling Reset by IDC control\n");
  583. qla83xx_idc_lock(vha, 0);
  584. __qla83xx_get_idc_control(vha, &idc_control);
  585. idc_control |= QLA83XX_IDC_RESET_DISABLED;
  586. __qla83xx_set_idc_control(vha, idc_control);
  587. qla83xx_idc_unlock(vha, 0);
  588. break;
  589. case 0x20260:
  590. if (!IS_QLA8031(ha))
  591. return -EPERM;
  592. ql_log(ql_log_info, vha, 0x70bd,
  593. "Enabling Reset by IDC control\n");
  594. qla83xx_idc_lock(vha, 0);
  595. __qla83xx_get_idc_control(vha, &idc_control);
  596. idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
  597. __qla83xx_set_idc_control(vha, idc_control);
  598. qla83xx_idc_unlock(vha, 0);
  599. break;
  600. }
  601. return count;
  602. }
  603. static struct bin_attribute sysfs_reset_attr = {
  604. .attr = {
  605. .name = "reset",
  606. .mode = S_IWUSR,
  607. },
  608. .size = 0,
  609. .write = qla2x00_sysfs_write_reset,
  610. };
  611. static ssize_t
  612. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  613. struct bin_attribute *bin_attr,
  614. char *buf, loff_t off, size_t count)
  615. {
  616. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  617. struct device, kobj)));
  618. struct qla_hw_data *ha = vha->hw;
  619. int rval;
  620. uint16_t actual_size;
  621. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  622. return 0;
  623. if (ha->xgmac_data)
  624. goto do_read;
  625. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  626. &ha->xgmac_data_dma, GFP_KERNEL);
  627. if (!ha->xgmac_data) {
  628. ql_log(ql_log_warn, vha, 0x7076,
  629. "Unable to allocate memory for XGMAC read-data.\n");
  630. return 0;
  631. }
  632. do_read:
  633. actual_size = 0;
  634. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  635. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  636. XGMAC_DATA_SIZE, &actual_size);
  637. if (rval != QLA_SUCCESS) {
  638. ql_log(ql_log_warn, vha, 0x7077,
  639. "Unable to read XGMAC data (%x).\n", rval);
  640. count = 0;
  641. }
  642. count = actual_size > count ? count: actual_size;
  643. memcpy(buf, ha->xgmac_data, count);
  644. return count;
  645. }
  646. static struct bin_attribute sysfs_xgmac_stats_attr = {
  647. .attr = {
  648. .name = "xgmac_stats",
  649. .mode = S_IRUSR,
  650. },
  651. .size = 0,
  652. .read = qla2x00_sysfs_read_xgmac_stats,
  653. };
  654. static ssize_t
  655. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  656. struct bin_attribute *bin_attr,
  657. char *buf, loff_t off, size_t count)
  658. {
  659. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  660. struct device, kobj)));
  661. struct qla_hw_data *ha = vha->hw;
  662. int rval;
  663. uint16_t actual_size;
  664. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  665. return 0;
  666. if (ha->dcbx_tlv)
  667. goto do_read;
  668. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  669. &ha->dcbx_tlv_dma, GFP_KERNEL);
  670. if (!ha->dcbx_tlv) {
  671. ql_log(ql_log_warn, vha, 0x7078,
  672. "Unable to allocate memory for DCBX TLV read-data.\n");
  673. return -ENOMEM;
  674. }
  675. do_read:
  676. actual_size = 0;
  677. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  678. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  679. DCBX_TLV_DATA_SIZE);
  680. if (rval != QLA_SUCCESS) {
  681. ql_log(ql_log_warn, vha, 0x7079,
  682. "Unable to read DCBX TLV (%x).\n", rval);
  683. return -EIO;
  684. }
  685. memcpy(buf, ha->dcbx_tlv, count);
  686. return count;
  687. }
  688. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  689. .attr = {
  690. .name = "dcbx_tlv",
  691. .mode = S_IRUSR,
  692. },
  693. .size = 0,
  694. .read = qla2x00_sysfs_read_dcbx_tlv,
  695. };
  696. static struct sysfs_entry {
  697. char *name;
  698. struct bin_attribute *attr;
  699. int is4GBp_only;
  700. } bin_file_entries[] = {
  701. { "fw_dump", &sysfs_fw_dump_attr, },
  702. { "nvram", &sysfs_nvram_attr, },
  703. { "optrom", &sysfs_optrom_attr, },
  704. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  705. { "vpd", &sysfs_vpd_attr, 1 },
  706. { "sfp", &sysfs_sfp_attr, 1 },
  707. { "reset", &sysfs_reset_attr, },
  708. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  709. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  710. { NULL },
  711. };
  712. void
  713. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  714. {
  715. struct Scsi_Host *host = vha->host;
  716. struct sysfs_entry *iter;
  717. int ret;
  718. for (iter = bin_file_entries; iter->name; iter++) {
  719. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  720. continue;
  721. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  722. continue;
  723. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  724. continue;
  725. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  726. iter->attr);
  727. if (ret)
  728. ql_log(ql_log_warn, vha, 0x00f3,
  729. "Unable to create sysfs %s binary attribute (%d).\n",
  730. iter->name, ret);
  731. else
  732. ql_dbg(ql_dbg_init, vha, 0x00f4,
  733. "Successfully created sysfs %s binary attribure.\n",
  734. iter->name);
  735. }
  736. }
  737. void
  738. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  739. {
  740. struct Scsi_Host *host = vha->host;
  741. struct sysfs_entry *iter;
  742. struct qla_hw_data *ha = vha->hw;
  743. for (iter = bin_file_entries; iter->name; iter++) {
  744. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  745. continue;
  746. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  747. continue;
  748. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  749. continue;
  750. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  751. iter->attr);
  752. }
  753. if (ha->beacon_blink_led == 1)
  754. ha->isp_ops->beacon_off(vha);
  755. }
  756. /* Scsi_Host attributes. */
  757. static ssize_t
  758. qla2x00_drvr_version_show(struct device *dev,
  759. struct device_attribute *attr, char *buf)
  760. {
  761. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  762. }
  763. static ssize_t
  764. qla2x00_fw_version_show(struct device *dev,
  765. struct device_attribute *attr, char *buf)
  766. {
  767. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  768. struct qla_hw_data *ha = vha->hw;
  769. char fw_str[128];
  770. return snprintf(buf, PAGE_SIZE, "%s\n",
  771. ha->isp_ops->fw_version_str(vha, fw_str));
  772. }
  773. static ssize_t
  774. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  775. char *buf)
  776. {
  777. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  778. struct qla_hw_data *ha = vha->hw;
  779. uint32_t sn;
  780. if (IS_QLAFX00(vha->hw)) {
  781. return snprintf(buf, PAGE_SIZE, "%s\n",
  782. vha->hw->mr.serial_num);
  783. } else if (IS_FWI2_CAPABLE(ha)) {
  784. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  785. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  786. }
  787. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  788. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  789. sn % 100000);
  790. }
  791. static ssize_t
  792. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  793. char *buf)
  794. {
  795. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  796. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  797. }
  798. static ssize_t
  799. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  800. char *buf)
  801. {
  802. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  803. struct qla_hw_data *ha = vha->hw;
  804. if (IS_QLAFX00(vha->hw))
  805. return snprintf(buf, PAGE_SIZE, "%s\n",
  806. vha->hw->mr.hw_version);
  807. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  808. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  809. ha->product_id[3]);
  810. }
  811. static ssize_t
  812. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  813. char *buf)
  814. {
  815. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  816. if (IS_QLAFX00(vha->hw))
  817. return snprintf(buf, PAGE_SIZE, "%s\n",
  818. vha->hw->mr.product_name);
  819. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  820. }
  821. static ssize_t
  822. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  823. char *buf)
  824. {
  825. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  826. return snprintf(buf, PAGE_SIZE, "%s\n",
  827. vha->hw->model_desc ? vha->hw->model_desc : "");
  828. }
  829. static ssize_t
  830. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  831. char *buf)
  832. {
  833. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  834. char pci_info[30];
  835. return snprintf(buf, PAGE_SIZE, "%s\n",
  836. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  837. }
  838. static ssize_t
  839. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  840. char *buf)
  841. {
  842. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  843. struct qla_hw_data *ha = vha->hw;
  844. int len = 0;
  845. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  846. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  847. vha->device_flags & DFLG_NO_CABLE)
  848. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  849. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  850. qla2x00_reset_active(vha))
  851. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  852. else {
  853. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  854. switch (ha->current_topology) {
  855. case ISP_CFG_NL:
  856. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  857. break;
  858. case ISP_CFG_FL:
  859. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  860. break;
  861. case ISP_CFG_N:
  862. len += snprintf(buf + len, PAGE_SIZE-len,
  863. "N_Port to N_Port\n");
  864. break;
  865. case ISP_CFG_F:
  866. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  867. break;
  868. default:
  869. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  870. break;
  871. }
  872. }
  873. return len;
  874. }
  875. static ssize_t
  876. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  877. char *buf)
  878. {
  879. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  880. int len = 0;
  881. switch (vha->hw->zio_mode) {
  882. case QLA_ZIO_MODE_6:
  883. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  884. break;
  885. case QLA_ZIO_DISABLED:
  886. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  887. break;
  888. }
  889. return len;
  890. }
  891. static ssize_t
  892. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  893. const char *buf, size_t count)
  894. {
  895. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  896. struct qla_hw_data *ha = vha->hw;
  897. int val = 0;
  898. uint16_t zio_mode;
  899. if (!IS_ZIO_SUPPORTED(ha))
  900. return -ENOTSUPP;
  901. if (sscanf(buf, "%d", &val) != 1)
  902. return -EINVAL;
  903. if (val)
  904. zio_mode = QLA_ZIO_MODE_6;
  905. else
  906. zio_mode = QLA_ZIO_DISABLED;
  907. /* Update per-hba values and queue a reset. */
  908. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  909. ha->zio_mode = zio_mode;
  910. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  911. }
  912. return strlen(buf);
  913. }
  914. static ssize_t
  915. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  916. char *buf)
  917. {
  918. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  919. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  920. }
  921. static ssize_t
  922. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  923. const char *buf, size_t count)
  924. {
  925. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  926. int val = 0;
  927. uint16_t zio_timer;
  928. if (sscanf(buf, "%d", &val) != 1)
  929. return -EINVAL;
  930. if (val > 25500 || val < 100)
  931. return -ERANGE;
  932. zio_timer = (uint16_t)(val / 100);
  933. vha->hw->zio_timer = zio_timer;
  934. return strlen(buf);
  935. }
  936. static ssize_t
  937. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  938. char *buf)
  939. {
  940. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  941. int len = 0;
  942. if (vha->hw->beacon_blink_led)
  943. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  944. else
  945. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  946. return len;
  947. }
  948. static ssize_t
  949. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  950. const char *buf, size_t count)
  951. {
  952. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  953. struct qla_hw_data *ha = vha->hw;
  954. int val = 0;
  955. int rval;
  956. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  957. return -EPERM;
  958. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  959. ql_log(ql_log_warn, vha, 0x707a,
  960. "Abort ISP active -- ignoring beacon request.\n");
  961. return -EBUSY;
  962. }
  963. if (sscanf(buf, "%d", &val) != 1)
  964. return -EINVAL;
  965. if (val)
  966. rval = ha->isp_ops->beacon_on(vha);
  967. else
  968. rval = ha->isp_ops->beacon_off(vha);
  969. if (rval != QLA_SUCCESS)
  970. count = 0;
  971. return count;
  972. }
  973. static ssize_t
  974. qla2x00_optrom_bios_version_show(struct device *dev,
  975. struct device_attribute *attr, char *buf)
  976. {
  977. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  978. struct qla_hw_data *ha = vha->hw;
  979. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  980. ha->bios_revision[0]);
  981. }
  982. static ssize_t
  983. qla2x00_optrom_efi_version_show(struct device *dev,
  984. struct device_attribute *attr, char *buf)
  985. {
  986. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  987. struct qla_hw_data *ha = vha->hw;
  988. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  989. ha->efi_revision[0]);
  990. }
  991. static ssize_t
  992. qla2x00_optrom_fcode_version_show(struct device *dev,
  993. struct device_attribute *attr, char *buf)
  994. {
  995. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  996. struct qla_hw_data *ha = vha->hw;
  997. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  998. ha->fcode_revision[0]);
  999. }
  1000. static ssize_t
  1001. qla2x00_optrom_fw_version_show(struct device *dev,
  1002. struct device_attribute *attr, char *buf)
  1003. {
  1004. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1005. struct qla_hw_data *ha = vha->hw;
  1006. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  1007. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  1008. ha->fw_revision[3]);
  1009. }
  1010. static ssize_t
  1011. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  1012. struct device_attribute *attr, char *buf)
  1013. {
  1014. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1015. struct qla_hw_data *ha = vha->hw;
  1016. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  1017. return snprintf(buf, PAGE_SIZE, "\n");
  1018. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  1019. ha->gold_fw_version[0], ha->gold_fw_version[1],
  1020. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  1021. }
  1022. static ssize_t
  1023. qla2x00_total_isp_aborts_show(struct device *dev,
  1024. struct device_attribute *attr, char *buf)
  1025. {
  1026. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1027. return snprintf(buf, PAGE_SIZE, "%d\n",
  1028. vha->qla_stats.total_isp_aborts);
  1029. }
  1030. static ssize_t
  1031. qla24xx_84xx_fw_version_show(struct device *dev,
  1032. struct device_attribute *attr, char *buf)
  1033. {
  1034. int rval = QLA_SUCCESS;
  1035. uint16_t status[2] = {0, 0};
  1036. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1037. struct qla_hw_data *ha = vha->hw;
  1038. if (!IS_QLA84XX(ha))
  1039. return snprintf(buf, PAGE_SIZE, "\n");
  1040. if (ha->cs84xx->op_fw_version == 0)
  1041. rval = qla84xx_verify_chip(vha, status);
  1042. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1043. return snprintf(buf, PAGE_SIZE, "%u\n",
  1044. (uint32_t)ha->cs84xx->op_fw_version);
  1045. return snprintf(buf, PAGE_SIZE, "\n");
  1046. }
  1047. static ssize_t
  1048. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1049. char *buf)
  1050. {
  1051. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1052. struct qla_hw_data *ha = vha->hw;
  1053. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
  1054. return snprintf(buf, PAGE_SIZE, "\n");
  1055. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1056. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1057. ha->mpi_capabilities);
  1058. }
  1059. static ssize_t
  1060. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1061. char *buf)
  1062. {
  1063. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1064. struct qla_hw_data *ha = vha->hw;
  1065. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  1066. return snprintf(buf, PAGE_SIZE, "\n");
  1067. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1068. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1069. }
  1070. static ssize_t
  1071. qla2x00_flash_block_size_show(struct device *dev,
  1072. struct device_attribute *attr, char *buf)
  1073. {
  1074. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1075. struct qla_hw_data *ha = vha->hw;
  1076. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1077. }
  1078. static ssize_t
  1079. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1080. char *buf)
  1081. {
  1082. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1083. if (!IS_CNA_CAPABLE(vha->hw))
  1084. return snprintf(buf, PAGE_SIZE, "\n");
  1085. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1086. }
  1087. static ssize_t
  1088. qla2x00_vn_port_mac_address_show(struct device *dev,
  1089. struct device_attribute *attr, char *buf)
  1090. {
  1091. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1092. if (!IS_CNA_CAPABLE(vha->hw))
  1093. return snprintf(buf, PAGE_SIZE, "\n");
  1094. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1095. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1096. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1097. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1098. }
  1099. static ssize_t
  1100. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1101. char *buf)
  1102. {
  1103. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1104. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1105. }
  1106. static ssize_t
  1107. qla2x00_thermal_temp_show(struct device *dev,
  1108. struct device_attribute *attr, char *buf)
  1109. {
  1110. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1111. uint16_t temp = 0;
  1112. if (!vha->hw->thermal_support) {
  1113. ql_log(ql_log_warn, vha, 0x70db,
  1114. "Thermal not supported by this card.\n");
  1115. goto done;
  1116. }
  1117. if (qla2x00_reset_active(vha)) {
  1118. ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
  1119. goto done;
  1120. }
  1121. if (vha->hw->flags.eeh_busy) {
  1122. ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
  1123. goto done;
  1124. }
  1125. if (qla2x00_get_thermal_temp(vha, &temp) == QLA_SUCCESS)
  1126. return snprintf(buf, PAGE_SIZE, "%d\n", temp);
  1127. done:
  1128. return snprintf(buf, PAGE_SIZE, "\n");
  1129. }
  1130. static ssize_t
  1131. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1132. char *buf)
  1133. {
  1134. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1135. int rval = QLA_FUNCTION_FAILED;
  1136. uint16_t state[5];
  1137. uint32_t pstate;
  1138. if (IS_QLAFX00(vha->hw)) {
  1139. pstate = qlafx00_fw_state_show(dev, attr, buf);
  1140. return snprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
  1141. }
  1142. if (qla2x00_reset_active(vha))
  1143. ql_log(ql_log_warn, vha, 0x707c,
  1144. "ISP reset active.\n");
  1145. else if (!vha->hw->flags.eeh_busy)
  1146. rval = qla2x00_get_firmware_state(vha, state);
  1147. if (rval != QLA_SUCCESS)
  1148. memset(state, -1, sizeof(state));
  1149. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1150. state[1], state[2], state[3], state[4]);
  1151. }
  1152. static ssize_t
  1153. qla2x00_diag_requests_show(struct device *dev,
  1154. struct device_attribute *attr, char *buf)
  1155. {
  1156. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1157. if (!IS_BIDI_CAPABLE(vha->hw))
  1158. return snprintf(buf, PAGE_SIZE, "\n");
  1159. return snprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
  1160. }
  1161. static ssize_t
  1162. qla2x00_diag_megabytes_show(struct device *dev,
  1163. struct device_attribute *attr, char *buf)
  1164. {
  1165. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1166. if (!IS_BIDI_CAPABLE(vha->hw))
  1167. return snprintf(buf, PAGE_SIZE, "\n");
  1168. return snprintf(buf, PAGE_SIZE, "%llu\n",
  1169. vha->bidi_stats.transfer_bytes >> 20);
  1170. }
  1171. static ssize_t
  1172. qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
  1173. char *buf)
  1174. {
  1175. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1176. struct qla_hw_data *ha = vha->hw;
  1177. uint32_t size;
  1178. if (!ha->fw_dumped)
  1179. size = 0;
  1180. else if (IS_QLA82XX(ha))
  1181. size = ha->md_template_size + ha->md_dump_size;
  1182. else
  1183. size = ha->fw_dump_len;
  1184. return snprintf(buf, PAGE_SIZE, "%d\n", size);
  1185. }
  1186. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1187. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1188. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1189. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1190. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1191. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1192. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1193. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1194. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1195. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1196. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1197. qla2x00_zio_timer_store);
  1198. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1199. qla2x00_beacon_store);
  1200. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1201. qla2x00_optrom_bios_version_show, NULL);
  1202. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1203. qla2x00_optrom_efi_version_show, NULL);
  1204. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1205. qla2x00_optrom_fcode_version_show, NULL);
  1206. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1207. NULL);
  1208. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1209. qla2x00_optrom_gold_fw_version_show, NULL);
  1210. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1211. NULL);
  1212. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1213. NULL);
  1214. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1215. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1216. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1217. NULL);
  1218. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1219. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1220. qla2x00_vn_port_mac_address_show, NULL);
  1221. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1222. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1223. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1224. static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
  1225. static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
  1226. static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
  1227. struct device_attribute *qla2x00_host_attrs[] = {
  1228. &dev_attr_driver_version,
  1229. &dev_attr_fw_version,
  1230. &dev_attr_serial_num,
  1231. &dev_attr_isp_name,
  1232. &dev_attr_isp_id,
  1233. &dev_attr_model_name,
  1234. &dev_attr_model_desc,
  1235. &dev_attr_pci_info,
  1236. &dev_attr_link_state,
  1237. &dev_attr_zio,
  1238. &dev_attr_zio_timer,
  1239. &dev_attr_beacon,
  1240. &dev_attr_optrom_bios_version,
  1241. &dev_attr_optrom_efi_version,
  1242. &dev_attr_optrom_fcode_version,
  1243. &dev_attr_optrom_fw_version,
  1244. &dev_attr_84xx_fw_version,
  1245. &dev_attr_total_isp_aborts,
  1246. &dev_attr_mpi_version,
  1247. &dev_attr_phy_version,
  1248. &dev_attr_flash_block_size,
  1249. &dev_attr_vlan_id,
  1250. &dev_attr_vn_port_mac_address,
  1251. &dev_attr_fabric_param,
  1252. &dev_attr_fw_state,
  1253. &dev_attr_optrom_gold_fw_version,
  1254. &dev_attr_thermal_temp,
  1255. &dev_attr_diag_requests,
  1256. &dev_attr_diag_megabytes,
  1257. &dev_attr_fw_dump_size,
  1258. NULL,
  1259. };
  1260. /* Host attributes. */
  1261. static void
  1262. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1263. {
  1264. scsi_qla_host_t *vha = shost_priv(shost);
  1265. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1266. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1267. }
  1268. static void
  1269. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1270. {
  1271. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1272. (shost_priv(shost)))->hw;
  1273. u32 speed = FC_PORTSPEED_UNKNOWN;
  1274. if (IS_QLAFX00(ha)) {
  1275. qlafx00_get_host_speed(shost);
  1276. return;
  1277. }
  1278. switch (ha->link_data_rate) {
  1279. case PORT_SPEED_1GB:
  1280. speed = FC_PORTSPEED_1GBIT;
  1281. break;
  1282. case PORT_SPEED_2GB:
  1283. speed = FC_PORTSPEED_2GBIT;
  1284. break;
  1285. case PORT_SPEED_4GB:
  1286. speed = FC_PORTSPEED_4GBIT;
  1287. break;
  1288. case PORT_SPEED_8GB:
  1289. speed = FC_PORTSPEED_8GBIT;
  1290. break;
  1291. case PORT_SPEED_10GB:
  1292. speed = FC_PORTSPEED_10GBIT;
  1293. break;
  1294. case PORT_SPEED_16GB:
  1295. speed = FC_PORTSPEED_16GBIT;
  1296. break;
  1297. }
  1298. fc_host_speed(shost) = speed;
  1299. }
  1300. static void
  1301. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1302. {
  1303. scsi_qla_host_t *vha = shost_priv(shost);
  1304. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1305. if (vha->vp_idx) {
  1306. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1307. return;
  1308. }
  1309. switch (vha->hw->current_topology) {
  1310. case ISP_CFG_NL:
  1311. port_type = FC_PORTTYPE_LPORT;
  1312. break;
  1313. case ISP_CFG_FL:
  1314. port_type = FC_PORTTYPE_NLPORT;
  1315. break;
  1316. case ISP_CFG_N:
  1317. port_type = FC_PORTTYPE_PTP;
  1318. break;
  1319. case ISP_CFG_F:
  1320. port_type = FC_PORTTYPE_NPORT;
  1321. break;
  1322. }
  1323. fc_host_port_type(shost) = port_type;
  1324. }
  1325. static void
  1326. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1327. {
  1328. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1329. scsi_qla_host_t *vha = shost_priv(host);
  1330. fc_port_t *fcport;
  1331. u64 node_name = 0;
  1332. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1333. if (fcport->rport &&
  1334. starget->id == fcport->rport->scsi_target_id) {
  1335. node_name = wwn_to_u64(fcport->node_name);
  1336. break;
  1337. }
  1338. }
  1339. fc_starget_node_name(starget) = node_name;
  1340. }
  1341. static void
  1342. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1343. {
  1344. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1345. scsi_qla_host_t *vha = shost_priv(host);
  1346. fc_port_t *fcport;
  1347. u64 port_name = 0;
  1348. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1349. if (fcport->rport &&
  1350. starget->id == fcport->rport->scsi_target_id) {
  1351. port_name = wwn_to_u64(fcport->port_name);
  1352. break;
  1353. }
  1354. }
  1355. fc_starget_port_name(starget) = port_name;
  1356. }
  1357. static void
  1358. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1359. {
  1360. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1361. scsi_qla_host_t *vha = shost_priv(host);
  1362. fc_port_t *fcport;
  1363. uint32_t port_id = ~0U;
  1364. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1365. if (fcport->rport &&
  1366. starget->id == fcport->rport->scsi_target_id) {
  1367. port_id = fcport->d_id.b.domain << 16 |
  1368. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1369. break;
  1370. }
  1371. }
  1372. fc_starget_port_id(starget) = port_id;
  1373. }
  1374. static void
  1375. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1376. {
  1377. if (timeout)
  1378. rport->dev_loss_tmo = timeout;
  1379. else
  1380. rport->dev_loss_tmo = 1;
  1381. }
  1382. static void
  1383. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1384. {
  1385. struct Scsi_Host *host = rport_to_shost(rport);
  1386. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1387. unsigned long flags;
  1388. if (!fcport)
  1389. return;
  1390. /* Now that the rport has been deleted, set the fcport state to
  1391. FCS_DEVICE_DEAD */
  1392. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1393. /*
  1394. * Transport has effectively 'deleted' the rport, clear
  1395. * all local references.
  1396. */
  1397. spin_lock_irqsave(host->host_lock, flags);
  1398. fcport->rport = fcport->drport = NULL;
  1399. *((fc_port_t **)rport->dd_data) = NULL;
  1400. spin_unlock_irqrestore(host->host_lock, flags);
  1401. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1402. return;
  1403. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1404. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1405. return;
  1406. }
  1407. }
  1408. static void
  1409. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1410. {
  1411. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1412. if (!fcport)
  1413. return;
  1414. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1415. return;
  1416. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1417. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1418. return;
  1419. }
  1420. /*
  1421. * At this point all fcport's software-states are cleared. Perform any
  1422. * final cleanup of firmware resources (PCBs and XCBs).
  1423. */
  1424. if (fcport->loop_id != FC_NO_LOOP_ID) {
  1425. if (IS_FWI2_CAPABLE(fcport->vha->hw))
  1426. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1427. fcport->loop_id, fcport->d_id.b.domain,
  1428. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1429. else
  1430. qla2x00_port_logout(fcport->vha, fcport);
  1431. }
  1432. }
  1433. static int
  1434. qla2x00_issue_lip(struct Scsi_Host *shost)
  1435. {
  1436. scsi_qla_host_t *vha = shost_priv(shost);
  1437. if (IS_QLAFX00(vha->hw))
  1438. return 0;
  1439. qla2x00_loop_reset(vha);
  1440. return 0;
  1441. }
  1442. static struct fc_host_statistics *
  1443. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1444. {
  1445. scsi_qla_host_t *vha = shost_priv(shost);
  1446. struct qla_hw_data *ha = vha->hw;
  1447. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1448. int rval;
  1449. struct link_statistics *stats;
  1450. dma_addr_t stats_dma;
  1451. struct fc_host_statistics *pfc_host_stat;
  1452. pfc_host_stat = &vha->fc_host_stat;
  1453. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1454. if (IS_QLAFX00(vha->hw))
  1455. goto done;
  1456. if (test_bit(UNLOADING, &vha->dpc_flags))
  1457. goto done;
  1458. if (unlikely(pci_channel_offline(ha->pdev)))
  1459. goto done;
  1460. if (qla2x00_reset_active(vha))
  1461. goto done;
  1462. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1463. if (stats == NULL) {
  1464. ql_log(ql_log_warn, vha, 0x707d,
  1465. "Failed to allocate memory for stats.\n");
  1466. goto done;
  1467. }
  1468. memset(stats, 0, DMA_POOL_SIZE);
  1469. rval = QLA_FUNCTION_FAILED;
  1470. if (IS_FWI2_CAPABLE(ha)) {
  1471. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1472. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1473. !ha->dpc_active) {
  1474. /* Must be in a 'READY' state for statistics retrieval. */
  1475. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1476. stats, stats_dma);
  1477. }
  1478. if (rval != QLA_SUCCESS)
  1479. goto done_free;
  1480. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1481. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1482. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1483. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1484. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1485. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1486. if (IS_FWI2_CAPABLE(ha)) {
  1487. pfc_host_stat->lip_count = stats->lip_cnt;
  1488. pfc_host_stat->tx_frames = stats->tx_frames;
  1489. pfc_host_stat->rx_frames = stats->rx_frames;
  1490. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1491. pfc_host_stat->nos_count = stats->nos_rcvd;
  1492. }
  1493. pfc_host_stat->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
  1494. pfc_host_stat->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
  1495. done_free:
  1496. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1497. done:
  1498. return pfc_host_stat;
  1499. }
  1500. static void
  1501. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1502. {
  1503. scsi_qla_host_t *vha = shost_priv(shost);
  1504. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1505. }
  1506. static void
  1507. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1508. {
  1509. scsi_qla_host_t *vha = shost_priv(shost);
  1510. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1511. }
  1512. static void
  1513. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1514. {
  1515. scsi_qla_host_t *vha = shost_priv(shost);
  1516. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1517. 0xFF, 0xFF, 0xFF, 0xFF};
  1518. u64 fabric_name = wwn_to_u64(node_name);
  1519. if (vha->device_flags & SWITCH_FOUND)
  1520. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1521. fc_host_fabric_name(shost) = fabric_name;
  1522. }
  1523. static void
  1524. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1525. {
  1526. scsi_qla_host_t *vha = shost_priv(shost);
  1527. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1528. if (!base_vha->flags.online) {
  1529. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1530. return;
  1531. }
  1532. switch (atomic_read(&base_vha->loop_state)) {
  1533. case LOOP_UPDATE:
  1534. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1535. break;
  1536. case LOOP_DOWN:
  1537. if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
  1538. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1539. else
  1540. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1541. break;
  1542. case LOOP_DEAD:
  1543. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1544. break;
  1545. case LOOP_READY:
  1546. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1547. break;
  1548. default:
  1549. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1550. break;
  1551. }
  1552. }
  1553. static int
  1554. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1555. {
  1556. int ret = 0;
  1557. uint8_t qos = 0;
  1558. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1559. scsi_qla_host_t *vha = NULL;
  1560. struct qla_hw_data *ha = base_vha->hw;
  1561. uint16_t options = 0;
  1562. int cnt;
  1563. struct req_que *req = ha->req_q_map[0];
  1564. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1565. if (ret) {
  1566. ql_log(ql_log_warn, vha, 0x707e,
  1567. "Vport sanity check failed, status %x\n", ret);
  1568. return (ret);
  1569. }
  1570. vha = qla24xx_create_vhost(fc_vport);
  1571. if (vha == NULL) {
  1572. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1573. return FC_VPORT_FAILED;
  1574. }
  1575. if (disable) {
  1576. atomic_set(&vha->vp_state, VP_OFFLINE);
  1577. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1578. } else
  1579. atomic_set(&vha->vp_state, VP_FAILED);
  1580. /* ready to create vport */
  1581. ql_log(ql_log_info, vha, 0x7080,
  1582. "VP entry id %d assigned.\n", vha->vp_idx);
  1583. /* initialized vport states */
  1584. atomic_set(&vha->loop_state, LOOP_DOWN);
  1585. vha->vp_err_state= VP_ERR_PORTDWN;
  1586. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1587. /* Check if physical ha port is Up */
  1588. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1589. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1590. /* Don't retry or attempt login of this virtual port */
  1591. ql_dbg(ql_dbg_user, vha, 0x7081,
  1592. "Vport loop state is not UP.\n");
  1593. atomic_set(&vha->loop_state, LOOP_DEAD);
  1594. if (!disable)
  1595. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1596. }
  1597. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  1598. if (ha->fw_attributes & BIT_4) {
  1599. int prot = 0, guard;
  1600. vha->flags.difdix_supported = 1;
  1601. ql_dbg(ql_dbg_user, vha, 0x7082,
  1602. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1603. if (ql2xenabledif == 1)
  1604. prot = SHOST_DIX_TYPE0_PROTECTION;
  1605. scsi_host_set_prot(vha->host,
  1606. prot | SHOST_DIF_TYPE1_PROTECTION
  1607. | SHOST_DIF_TYPE2_PROTECTION
  1608. | SHOST_DIF_TYPE3_PROTECTION
  1609. | SHOST_DIX_TYPE1_PROTECTION
  1610. | SHOST_DIX_TYPE2_PROTECTION
  1611. | SHOST_DIX_TYPE3_PROTECTION);
  1612. guard = SHOST_DIX_GUARD_CRC;
  1613. if (IS_PI_IPGUARD_CAPABLE(ha) &&
  1614. (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
  1615. guard |= SHOST_DIX_GUARD_IP;
  1616. scsi_host_set_guard(vha->host, guard);
  1617. } else
  1618. vha->flags.difdix_supported = 0;
  1619. }
  1620. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1621. &ha->pdev->dev)) {
  1622. ql_dbg(ql_dbg_user, vha, 0x7083,
  1623. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1624. goto vport_create_failed_2;
  1625. }
  1626. /* initialize attributes */
  1627. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1628. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1629. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1630. fc_host_supported_classes(vha->host) =
  1631. fc_host_supported_classes(base_vha->host);
  1632. fc_host_supported_speeds(vha->host) =
  1633. fc_host_supported_speeds(base_vha->host);
  1634. qlt_vport_create(vha, ha);
  1635. qla24xx_vport_disable(fc_vport, disable);
  1636. if (ha->flags.cpu_affinity_enabled) {
  1637. req = ha->req_q_map[1];
  1638. ql_dbg(ql_dbg_multiq, vha, 0xc000,
  1639. "Request queue %p attached with "
  1640. "VP[%d], cpu affinity =%d\n",
  1641. req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
  1642. goto vport_queue;
  1643. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1644. goto vport_queue;
  1645. /* Create a request queue in QoS mode for the vport */
  1646. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1647. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1648. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1649. 8) == 0) {
  1650. qos = ha->npiv_info[cnt].q_qos;
  1651. break;
  1652. }
  1653. }
  1654. if (qos) {
  1655. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1656. qos);
  1657. if (!ret)
  1658. ql_log(ql_log_warn, vha, 0x7084,
  1659. "Can't create request queue for VP[%d]\n",
  1660. vha->vp_idx);
  1661. else {
  1662. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1663. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1664. ret, qos, vha->vp_idx);
  1665. ql_dbg(ql_dbg_user, vha, 0x7085,
  1666. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1667. ret, qos, vha->vp_idx);
  1668. req = ha->req_q_map[ret];
  1669. }
  1670. }
  1671. vport_queue:
  1672. vha->req = req;
  1673. return 0;
  1674. vport_create_failed_2:
  1675. qla24xx_disable_vp(vha);
  1676. qla24xx_deallocate_vp_id(vha);
  1677. scsi_host_put(vha->host);
  1678. return FC_VPORT_FAILED;
  1679. }
  1680. static int
  1681. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1682. {
  1683. scsi_qla_host_t *vha = fc_vport->dd_data;
  1684. struct qla_hw_data *ha = vha->hw;
  1685. uint16_t id = vha->vp_idx;
  1686. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1687. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1688. msleep(1000);
  1689. qla24xx_disable_vp(vha);
  1690. vha->flags.delete_progress = 1;
  1691. fc_remove_host(vha->host);
  1692. scsi_remove_host(vha->host);
  1693. /* Allow timer to run to drain queued items, when removing vp */
  1694. qla24xx_deallocate_vp_id(vha);
  1695. if (vha->timer_active) {
  1696. qla2x00_vp_stop_timer(vha);
  1697. ql_dbg(ql_dbg_user, vha, 0x7086,
  1698. "Timer for the VP[%d] has stopped\n", vha->vp_idx);
  1699. }
  1700. BUG_ON(atomic_read(&vha->vref_count));
  1701. qla2x00_free_fcports(vha);
  1702. mutex_lock(&ha->vport_lock);
  1703. ha->cur_vport_count--;
  1704. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1705. mutex_unlock(&ha->vport_lock);
  1706. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1707. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1708. ql_log(ql_log_warn, vha, 0x7087,
  1709. "Queue delete failed.\n");
  1710. }
  1711. ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
  1712. scsi_host_put(vha->host);
  1713. return 0;
  1714. }
  1715. static int
  1716. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1717. {
  1718. scsi_qla_host_t *vha = fc_vport->dd_data;
  1719. if (disable)
  1720. qla24xx_disable_vp(vha);
  1721. else
  1722. qla24xx_enable_vp(vha);
  1723. return 0;
  1724. }
  1725. struct fc_function_template qla2xxx_transport_functions = {
  1726. .show_host_node_name = 1,
  1727. .show_host_port_name = 1,
  1728. .show_host_supported_classes = 1,
  1729. .show_host_supported_speeds = 1,
  1730. .get_host_port_id = qla2x00_get_host_port_id,
  1731. .show_host_port_id = 1,
  1732. .get_host_speed = qla2x00_get_host_speed,
  1733. .show_host_speed = 1,
  1734. .get_host_port_type = qla2x00_get_host_port_type,
  1735. .show_host_port_type = 1,
  1736. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1737. .show_host_symbolic_name = 1,
  1738. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1739. .show_host_system_hostname = 1,
  1740. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1741. .show_host_fabric_name = 1,
  1742. .get_host_port_state = qla2x00_get_host_port_state,
  1743. .show_host_port_state = 1,
  1744. .dd_fcrport_size = sizeof(struct fc_port *),
  1745. .show_rport_supported_classes = 1,
  1746. .get_starget_node_name = qla2x00_get_starget_node_name,
  1747. .show_starget_node_name = 1,
  1748. .get_starget_port_name = qla2x00_get_starget_port_name,
  1749. .show_starget_port_name = 1,
  1750. .get_starget_port_id = qla2x00_get_starget_port_id,
  1751. .show_starget_port_id = 1,
  1752. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1753. .show_rport_dev_loss_tmo = 1,
  1754. .issue_fc_host_lip = qla2x00_issue_lip,
  1755. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1756. .terminate_rport_io = qla2x00_terminate_rport_io,
  1757. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1758. .vport_create = qla24xx_vport_create,
  1759. .vport_disable = qla24xx_vport_disable,
  1760. .vport_delete = qla24xx_vport_delete,
  1761. .bsg_request = qla24xx_bsg_request,
  1762. .bsg_timeout = qla24xx_bsg_timeout,
  1763. };
  1764. struct fc_function_template qla2xxx_transport_vport_functions = {
  1765. .show_host_node_name = 1,
  1766. .show_host_port_name = 1,
  1767. .show_host_supported_classes = 1,
  1768. .get_host_port_id = qla2x00_get_host_port_id,
  1769. .show_host_port_id = 1,
  1770. .get_host_speed = qla2x00_get_host_speed,
  1771. .show_host_speed = 1,
  1772. .get_host_port_type = qla2x00_get_host_port_type,
  1773. .show_host_port_type = 1,
  1774. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1775. .show_host_symbolic_name = 1,
  1776. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1777. .show_host_system_hostname = 1,
  1778. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1779. .show_host_fabric_name = 1,
  1780. .get_host_port_state = qla2x00_get_host_port_state,
  1781. .show_host_port_state = 1,
  1782. .dd_fcrport_size = sizeof(struct fc_port *),
  1783. .show_rport_supported_classes = 1,
  1784. .get_starget_node_name = qla2x00_get_starget_node_name,
  1785. .show_starget_node_name = 1,
  1786. .get_starget_port_name = qla2x00_get_starget_port_name,
  1787. .show_starget_port_name = 1,
  1788. .get_starget_port_id = qla2x00_get_starget_port_id,
  1789. .show_starget_port_id = 1,
  1790. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1791. .show_rport_dev_loss_tmo = 1,
  1792. .issue_fc_host_lip = qla2x00_issue_lip,
  1793. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1794. .terminate_rport_io = qla2x00_terminate_rport_io,
  1795. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1796. .bsg_request = qla24xx_bsg_request,
  1797. .bsg_timeout = qla24xx_bsg_timeout,
  1798. };
  1799. void
  1800. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1801. {
  1802. struct qla_hw_data *ha = vha->hw;
  1803. u32 speed = FC_PORTSPEED_UNKNOWN;
  1804. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1805. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1806. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1807. fc_host_supported_classes(vha->host) = ha->tgt.enable_class_2 ?
  1808. (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
  1809. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1810. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1811. if (IS_CNA_CAPABLE(ha))
  1812. speed = FC_PORTSPEED_10GBIT;
  1813. else if (IS_QLA2031(ha))
  1814. speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
  1815. FC_PORTSPEED_4GBIT;
  1816. else if (IS_QLA25XX(ha))
  1817. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1818. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1819. else if (IS_QLA24XX_TYPE(ha))
  1820. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1821. FC_PORTSPEED_1GBIT;
  1822. else if (IS_QLA23XX(ha))
  1823. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1824. else if (IS_QLAFX00(ha))
  1825. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1826. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1827. else
  1828. speed = FC_PORTSPEED_1GBIT;
  1829. fc_host_supported_speeds(vha->host) = speed;
  1830. }