qla_attr.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/kthread.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/slab.h>
  11. #include <linux/delay.h>
  12. static int qla24xx_vport_disable(struct fc_vport *, bool);
  13. static int qla84xx_reset(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  14. int qla84xx_reset_chip(scsi_qla_host_t *, uint16_t, uint16_t *);
  15. static int qla84xx_mgmt_cmd(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  16. /* SYSFS attributes --------------------------------------------------------- */
  17. static ssize_t
  18. qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
  19. struct bin_attribute *bin_attr,
  20. char *buf, loff_t off, size_t count)
  21. {
  22. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  23. struct device, kobj)));
  24. struct qla_hw_data *ha = vha->hw;
  25. if (ha->fw_dump_reading == 0)
  26. return 0;
  27. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  28. ha->fw_dump_len);
  29. }
  30. static ssize_t
  31. qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
  32. struct bin_attribute *bin_attr,
  33. char *buf, loff_t off, size_t count)
  34. {
  35. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  36. struct device, kobj)));
  37. struct qla_hw_data *ha = vha->hw;
  38. int reading;
  39. if (off != 0)
  40. return (0);
  41. reading = simple_strtol(buf, NULL, 10);
  42. switch (reading) {
  43. case 0:
  44. if (!ha->fw_dump_reading)
  45. break;
  46. qla_printk(KERN_INFO, ha,
  47. "Firmware dump cleared on (%ld).\n", vha->host_no);
  48. ha->fw_dump_reading = 0;
  49. ha->fw_dumped = 0;
  50. break;
  51. case 1:
  52. if (ha->fw_dumped && !ha->fw_dump_reading) {
  53. ha->fw_dump_reading = 1;
  54. qla_printk(KERN_INFO, ha,
  55. "Raw firmware dump ready for read on (%ld).\n",
  56. vha->host_no);
  57. }
  58. break;
  59. case 2:
  60. qla2x00_alloc_fw_dump(vha);
  61. break;
  62. case 3:
  63. qla2x00_system_error(vha);
  64. break;
  65. }
  66. return (count);
  67. }
  68. static struct bin_attribute sysfs_fw_dump_attr = {
  69. .attr = {
  70. .name = "fw_dump",
  71. .mode = S_IRUSR | S_IWUSR,
  72. },
  73. .size = 0,
  74. .read = qla2x00_sysfs_read_fw_dump,
  75. .write = qla2x00_sysfs_write_fw_dump,
  76. };
  77. static ssize_t
  78. qla2x00_sysfs_read_nvram(struct kobject *kobj,
  79. struct bin_attribute *bin_attr,
  80. char *buf, loff_t off, size_t count)
  81. {
  82. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  83. struct device, kobj)));
  84. struct qla_hw_data *ha = vha->hw;
  85. if (!capable(CAP_SYS_ADMIN))
  86. return 0;
  87. if (IS_NOCACHE_VPD_TYPE(ha))
  88. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  89. ha->nvram_size);
  90. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  91. ha->nvram_size);
  92. }
  93. static ssize_t
  94. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  95. struct bin_attribute *bin_attr,
  96. char *buf, loff_t off, size_t count)
  97. {
  98. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  99. struct device, kobj)));
  100. struct qla_hw_data *ha = vha->hw;
  101. uint16_t cnt;
  102. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  103. !ha->isp_ops->write_nvram)
  104. return 0;
  105. /* Checksum NVRAM. */
  106. if (IS_FWI2_CAPABLE(ha)) {
  107. uint32_t *iter;
  108. uint32_t chksum;
  109. iter = (uint32_t *)buf;
  110. chksum = 0;
  111. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  112. chksum += le32_to_cpu(*iter++);
  113. chksum = ~chksum + 1;
  114. *iter = cpu_to_le32(chksum);
  115. } else {
  116. uint8_t *iter;
  117. uint8_t chksum;
  118. iter = (uint8_t *)buf;
  119. chksum = 0;
  120. for (cnt = 0; cnt < count - 1; cnt++)
  121. chksum += *iter++;
  122. chksum = ~chksum + 1;
  123. *iter = chksum;
  124. }
  125. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  126. qla_printk(KERN_WARNING, ha,
  127. "HBA not online, failing NVRAM update.\n");
  128. return -EAGAIN;
  129. }
  130. /* Write NVRAM. */
  131. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  132. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  133. count);
  134. /* NVRAM settings take effect immediately. */
  135. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  136. qla2xxx_wake_dpc(vha);
  137. qla2x00_wait_for_chip_reset(vha);
  138. return (count);
  139. }
  140. static struct bin_attribute sysfs_nvram_attr = {
  141. .attr = {
  142. .name = "nvram",
  143. .mode = S_IRUSR | S_IWUSR,
  144. },
  145. .size = 512,
  146. .read = qla2x00_sysfs_read_nvram,
  147. .write = qla2x00_sysfs_write_nvram,
  148. };
  149. static ssize_t
  150. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  151. struct bin_attribute *bin_attr,
  152. char *buf, loff_t off, size_t count)
  153. {
  154. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  155. struct device, kobj)));
  156. struct qla_hw_data *ha = vha->hw;
  157. if (ha->optrom_state != QLA_SREADING)
  158. return 0;
  159. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  160. ha->optrom_region_size);
  161. }
  162. static ssize_t
  163. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  164. struct bin_attribute *bin_attr,
  165. char *buf, loff_t off, size_t count)
  166. {
  167. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  168. struct device, kobj)));
  169. struct qla_hw_data *ha = vha->hw;
  170. if (ha->optrom_state != QLA_SWRITING)
  171. return -EINVAL;
  172. if (off > ha->optrom_region_size)
  173. return -ERANGE;
  174. if (off + count > ha->optrom_region_size)
  175. count = ha->optrom_region_size - off;
  176. memcpy(&ha->optrom_buffer[off], buf, count);
  177. return count;
  178. }
  179. static struct bin_attribute sysfs_optrom_attr = {
  180. .attr = {
  181. .name = "optrom",
  182. .mode = S_IRUSR | S_IWUSR,
  183. },
  184. .size = 0,
  185. .read = qla2x00_sysfs_read_optrom,
  186. .write = qla2x00_sysfs_write_optrom,
  187. };
  188. static ssize_t
  189. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  190. struct bin_attribute *bin_attr,
  191. char *buf, loff_t off, size_t count)
  192. {
  193. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  194. struct device, kobj)));
  195. struct qla_hw_data *ha = vha->hw;
  196. uint32_t start = 0;
  197. uint32_t size = ha->optrom_size;
  198. int val, valid;
  199. if (off)
  200. return 0;
  201. if (unlikely(pci_channel_offline(ha->pdev)))
  202. return 0;
  203. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  204. return -EINVAL;
  205. if (start > ha->optrom_size)
  206. return -EINVAL;
  207. switch (val) {
  208. case 0:
  209. if (ha->optrom_state != QLA_SREADING &&
  210. ha->optrom_state != QLA_SWRITING)
  211. break;
  212. ha->optrom_state = QLA_SWAITING;
  213. DEBUG2(qla_printk(KERN_INFO, ha,
  214. "Freeing flash region allocation -- 0x%x bytes.\n",
  215. ha->optrom_region_size));
  216. vfree(ha->optrom_buffer);
  217. ha->optrom_buffer = NULL;
  218. break;
  219. case 1:
  220. if (ha->optrom_state != QLA_SWAITING)
  221. break;
  222. ha->optrom_region_start = start;
  223. ha->optrom_region_size = start + size > ha->optrom_size ?
  224. ha->optrom_size - start : size;
  225. ha->optrom_state = QLA_SREADING;
  226. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  227. if (ha->optrom_buffer == NULL) {
  228. qla_printk(KERN_WARNING, ha,
  229. "Unable to allocate memory for optrom retrieval "
  230. "(%x).\n", ha->optrom_region_size);
  231. ha->optrom_state = QLA_SWAITING;
  232. return count;
  233. }
  234. DEBUG2(qla_printk(KERN_INFO, ha,
  235. "Reading flash region -- 0x%x/0x%x.\n",
  236. ha->optrom_region_start, ha->optrom_region_size));
  237. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  238. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  239. ha->optrom_region_start, ha->optrom_region_size);
  240. break;
  241. case 2:
  242. if (ha->optrom_state != QLA_SWAITING)
  243. break;
  244. /*
  245. * We need to be more restrictive on which FLASH regions are
  246. * allowed to be updated via user-space. Regions accessible
  247. * via this method include:
  248. *
  249. * ISP21xx/ISP22xx/ISP23xx type boards:
  250. *
  251. * 0x000000 -> 0x020000 -- Boot code.
  252. *
  253. * ISP2322/ISP24xx type boards:
  254. *
  255. * 0x000000 -> 0x07ffff -- Boot code.
  256. * 0x080000 -> 0x0fffff -- Firmware.
  257. *
  258. * ISP25xx type boards:
  259. *
  260. * 0x000000 -> 0x07ffff -- Boot code.
  261. * 0x080000 -> 0x0fffff -- Firmware.
  262. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  263. */
  264. valid = 0;
  265. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  266. valid = 1;
  267. else if (start == (ha->flt_region_boot * 4) ||
  268. start == (ha->flt_region_fw * 4))
  269. valid = 1;
  270. else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
  271. valid = 1;
  272. if (!valid) {
  273. qla_printk(KERN_WARNING, ha,
  274. "Invalid start region 0x%x/0x%x.\n", start, size);
  275. return -EINVAL;
  276. }
  277. ha->optrom_region_start = start;
  278. ha->optrom_region_size = start + size > ha->optrom_size ?
  279. ha->optrom_size - start : size;
  280. ha->optrom_state = QLA_SWRITING;
  281. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  282. if (ha->optrom_buffer == NULL) {
  283. qla_printk(KERN_WARNING, ha,
  284. "Unable to allocate memory for optrom update "
  285. "(%x).\n", ha->optrom_region_size);
  286. ha->optrom_state = QLA_SWAITING;
  287. return count;
  288. }
  289. DEBUG2(qla_printk(KERN_INFO, ha,
  290. "Staging flash region write -- 0x%x/0x%x.\n",
  291. ha->optrom_region_start, ha->optrom_region_size));
  292. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  293. break;
  294. case 3:
  295. if (ha->optrom_state != QLA_SWRITING)
  296. break;
  297. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  298. qla_printk(KERN_WARNING, ha,
  299. "HBA not online, failing flash update.\n");
  300. return -EAGAIN;
  301. }
  302. DEBUG2(qla_printk(KERN_INFO, ha,
  303. "Writing flash region -- 0x%x/0x%x.\n",
  304. ha->optrom_region_start, ha->optrom_region_size));
  305. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  306. ha->optrom_region_start, ha->optrom_region_size);
  307. break;
  308. default:
  309. count = -EINVAL;
  310. }
  311. return count;
  312. }
  313. static struct bin_attribute sysfs_optrom_ctl_attr = {
  314. .attr = {
  315. .name = "optrom_ctl",
  316. .mode = S_IWUSR,
  317. },
  318. .size = 0,
  319. .write = qla2x00_sysfs_write_optrom_ctl,
  320. };
  321. static ssize_t
  322. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  323. struct bin_attribute *bin_attr,
  324. char *buf, loff_t off, size_t count)
  325. {
  326. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  327. struct device, kobj)));
  328. struct qla_hw_data *ha = vha->hw;
  329. if (unlikely(pci_channel_offline(ha->pdev)))
  330. return 0;
  331. if (!capable(CAP_SYS_ADMIN))
  332. return 0;
  333. if (IS_NOCACHE_VPD_TYPE(ha))
  334. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  335. ha->vpd_size);
  336. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  337. }
  338. static ssize_t
  339. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  340. struct bin_attribute *bin_attr,
  341. char *buf, loff_t off, size_t count)
  342. {
  343. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  344. struct device, kobj)));
  345. struct qla_hw_data *ha = vha->hw;
  346. uint8_t *tmp_data;
  347. if (unlikely(pci_channel_offline(ha->pdev)))
  348. return 0;
  349. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  350. !ha->isp_ops->write_nvram)
  351. return 0;
  352. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  353. qla_printk(KERN_WARNING, ha,
  354. "HBA not online, failing VPD update.\n");
  355. return -EAGAIN;
  356. }
  357. /* Write NVRAM. */
  358. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  359. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  360. /* Update flash version information for 4Gb & above. */
  361. if (!IS_FWI2_CAPABLE(ha))
  362. goto done;
  363. tmp_data = vmalloc(256);
  364. if (!tmp_data) {
  365. qla_printk(KERN_WARNING, ha,
  366. "Unable to allocate memory for VPD information update.\n");
  367. goto done;
  368. }
  369. ha->isp_ops->get_flash_version(vha, tmp_data);
  370. vfree(tmp_data);
  371. done:
  372. return count;
  373. }
  374. static struct bin_attribute sysfs_vpd_attr = {
  375. .attr = {
  376. .name = "vpd",
  377. .mode = S_IRUSR | S_IWUSR,
  378. },
  379. .size = 0,
  380. .read = qla2x00_sysfs_read_vpd,
  381. .write = qla2x00_sysfs_write_vpd,
  382. };
  383. static ssize_t
  384. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  385. struct bin_attribute *bin_attr,
  386. char *buf, loff_t off, size_t count)
  387. {
  388. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  389. struct device, kobj)));
  390. struct qla_hw_data *ha = vha->hw;
  391. uint16_t iter, addr, offset;
  392. int rval;
  393. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  394. return 0;
  395. if (ha->sfp_data)
  396. goto do_read;
  397. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  398. &ha->sfp_data_dma);
  399. if (!ha->sfp_data) {
  400. qla_printk(KERN_WARNING, ha,
  401. "Unable to allocate memory for SFP read-data.\n");
  402. return 0;
  403. }
  404. do_read:
  405. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  406. addr = 0xa0;
  407. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  408. iter++, offset += SFP_BLOCK_SIZE) {
  409. if (iter == 4) {
  410. /* Skip to next device address. */
  411. addr = 0xa2;
  412. offset = 0;
  413. }
  414. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  415. SFP_BLOCK_SIZE);
  416. if (rval != QLA_SUCCESS) {
  417. qla_printk(KERN_WARNING, ha,
  418. "Unable to read SFP data (%x/%x/%x).\n", rval,
  419. addr, offset);
  420. count = 0;
  421. break;
  422. }
  423. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  424. buf += SFP_BLOCK_SIZE;
  425. }
  426. return count;
  427. }
  428. static struct bin_attribute sysfs_sfp_attr = {
  429. .attr = {
  430. .name = "sfp",
  431. .mode = S_IRUSR | S_IWUSR,
  432. },
  433. .size = SFP_DEV_SIZE * 2,
  434. .read = qla2x00_sysfs_read_sfp,
  435. };
  436. static ssize_t
  437. qla2x00_sysfs_write_reset(struct kobject *kobj,
  438. struct bin_attribute *bin_attr,
  439. char *buf, loff_t off, size_t count)
  440. {
  441. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  442. struct device, kobj)));
  443. struct qla_hw_data *ha = vha->hw;
  444. int type;
  445. if (off != 0)
  446. return 0;
  447. type = simple_strtol(buf, NULL, 10);
  448. switch (type) {
  449. case 0x2025c:
  450. qla_printk(KERN_INFO, ha,
  451. "Issuing ISP reset on (%ld).\n", vha->host_no);
  452. scsi_block_requests(vha->host);
  453. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  454. qla2xxx_wake_dpc(vha);
  455. qla2x00_wait_for_chip_reset(vha);
  456. scsi_unblock_requests(vha->host);
  457. break;
  458. case 0x2025d:
  459. if (!IS_QLA81XX(ha))
  460. break;
  461. qla_printk(KERN_INFO, ha,
  462. "Issuing MPI reset on (%ld).\n", vha->host_no);
  463. /* Make sure FC side is not in reset */
  464. qla2x00_wait_for_hba_online(vha);
  465. /* Issue MPI reset */
  466. scsi_block_requests(vha->host);
  467. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  468. qla_printk(KERN_WARNING, ha,
  469. "MPI reset failed on (%ld).\n", vha->host_no);
  470. scsi_unblock_requests(vha->host);
  471. break;
  472. }
  473. return count;
  474. }
  475. static struct bin_attribute sysfs_reset_attr = {
  476. .attr = {
  477. .name = "reset",
  478. .mode = S_IWUSR,
  479. },
  480. .size = 0,
  481. .write = qla2x00_sysfs_write_reset,
  482. };
  483. static ssize_t
  484. qla2x00_sysfs_write_edc(struct kobject *kobj,
  485. struct bin_attribute *bin_attr,
  486. char *buf, loff_t off, size_t count)
  487. {
  488. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  489. struct device, kobj)));
  490. struct qla_hw_data *ha = vha->hw;
  491. uint16_t dev, adr, opt, len;
  492. int rval;
  493. ha->edc_data_len = 0;
  494. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  495. return 0;
  496. if (!ha->edc_data) {
  497. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  498. &ha->edc_data_dma);
  499. if (!ha->edc_data) {
  500. DEBUG2(qla_printk(KERN_INFO, ha,
  501. "Unable to allocate memory for EDC write.\n"));
  502. return 0;
  503. }
  504. }
  505. dev = le16_to_cpup((void *)&buf[0]);
  506. adr = le16_to_cpup((void *)&buf[2]);
  507. opt = le16_to_cpup((void *)&buf[4]);
  508. len = le16_to_cpup((void *)&buf[6]);
  509. if (!(opt & BIT_0))
  510. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  511. return -EINVAL;
  512. memcpy(ha->edc_data, &buf[8], len);
  513. rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
  514. ha->edc_data, len, opt);
  515. if (rval != QLA_SUCCESS) {
  516. DEBUG2(qla_printk(KERN_INFO, ha,
  517. "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
  518. rval, dev, adr, opt, len, *buf));
  519. return 0;
  520. }
  521. return count;
  522. }
  523. static struct bin_attribute sysfs_edc_attr = {
  524. .attr = {
  525. .name = "edc",
  526. .mode = S_IWUSR,
  527. },
  528. .size = 0,
  529. .write = qla2x00_sysfs_write_edc,
  530. };
  531. static ssize_t
  532. qla2x00_sysfs_write_edc_status(struct kobject *kobj,
  533. struct bin_attribute *bin_attr,
  534. char *buf, loff_t off, size_t count)
  535. {
  536. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  537. struct device, kobj)));
  538. struct qla_hw_data *ha = vha->hw;
  539. uint16_t dev, adr, opt, len;
  540. int rval;
  541. ha->edc_data_len = 0;
  542. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  543. return 0;
  544. if (!ha->edc_data) {
  545. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  546. &ha->edc_data_dma);
  547. if (!ha->edc_data) {
  548. DEBUG2(qla_printk(KERN_INFO, ha,
  549. "Unable to allocate memory for EDC status.\n"));
  550. return 0;
  551. }
  552. }
  553. dev = le16_to_cpup((void *)&buf[0]);
  554. adr = le16_to_cpup((void *)&buf[2]);
  555. opt = le16_to_cpup((void *)&buf[4]);
  556. len = le16_to_cpup((void *)&buf[6]);
  557. if (!(opt & BIT_0))
  558. if (len == 0 || len > DMA_POOL_SIZE)
  559. return -EINVAL;
  560. memset(ha->edc_data, 0, len);
  561. rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
  562. ha->edc_data, len, opt);
  563. if (rval != QLA_SUCCESS) {
  564. DEBUG2(qla_printk(KERN_INFO, ha,
  565. "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
  566. rval, dev, adr, opt, len));
  567. return 0;
  568. }
  569. ha->edc_data_len = len;
  570. return count;
  571. }
  572. static ssize_t
  573. qla2x00_sysfs_read_edc_status(struct kobject *kobj,
  574. struct bin_attribute *bin_attr,
  575. char *buf, loff_t off, size_t count)
  576. {
  577. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  578. struct device, kobj)));
  579. struct qla_hw_data *ha = vha->hw;
  580. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  581. return 0;
  582. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  583. return -EINVAL;
  584. memcpy(buf, ha->edc_data, ha->edc_data_len);
  585. return ha->edc_data_len;
  586. }
  587. static struct bin_attribute sysfs_edc_status_attr = {
  588. .attr = {
  589. .name = "edc_status",
  590. .mode = S_IRUSR | S_IWUSR,
  591. },
  592. .size = 0,
  593. .write = qla2x00_sysfs_write_edc_status,
  594. .read = qla2x00_sysfs_read_edc_status,
  595. };
  596. static ssize_t
  597. qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
  598. struct bin_attribute *bin_attr,
  599. char *buf, loff_t off, size_t count)
  600. {
  601. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  602. struct device, kobj)));
  603. struct qla_hw_data *ha = vha->hw;
  604. int rval;
  605. uint16_t actual_size;
  606. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  607. return 0;
  608. if (ha->xgmac_data)
  609. goto do_read;
  610. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  611. &ha->xgmac_data_dma, GFP_KERNEL);
  612. if (!ha->xgmac_data) {
  613. qla_printk(KERN_WARNING, ha,
  614. "Unable to allocate memory for XGMAC read-data.\n");
  615. return 0;
  616. }
  617. do_read:
  618. actual_size = 0;
  619. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  620. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  621. XGMAC_DATA_SIZE, &actual_size);
  622. if (rval != QLA_SUCCESS) {
  623. qla_printk(KERN_WARNING, ha,
  624. "Unable to read XGMAC data (%x).\n", rval);
  625. count = 0;
  626. }
  627. count = actual_size > count ? count: actual_size;
  628. memcpy(buf, ha->xgmac_data, count);
  629. return count;
  630. }
  631. static struct bin_attribute sysfs_xgmac_stats_attr = {
  632. .attr = {
  633. .name = "xgmac_stats",
  634. .mode = S_IRUSR,
  635. },
  636. .size = 0,
  637. .read = qla2x00_sysfs_read_xgmac_stats,
  638. };
  639. static ssize_t
  640. qla2x00_sysfs_read_dcbx_tlv(struct kobject *kobj,
  641. struct bin_attribute *bin_attr,
  642. char *buf, loff_t off, size_t count)
  643. {
  644. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  645. struct device, kobj)));
  646. struct qla_hw_data *ha = vha->hw;
  647. int rval;
  648. uint16_t actual_size;
  649. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  650. return 0;
  651. if (ha->dcbx_tlv)
  652. goto do_read;
  653. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  654. &ha->dcbx_tlv_dma, GFP_KERNEL);
  655. if (!ha->dcbx_tlv) {
  656. qla_printk(KERN_WARNING, ha,
  657. "Unable to allocate memory for DCBX TLV read-data.\n");
  658. return 0;
  659. }
  660. do_read:
  661. actual_size = 0;
  662. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  663. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  664. DCBX_TLV_DATA_SIZE);
  665. if (rval != QLA_SUCCESS) {
  666. qla_printk(KERN_WARNING, ha,
  667. "Unable to read DCBX TLV data (%x).\n", rval);
  668. count = 0;
  669. }
  670. memcpy(buf, ha->dcbx_tlv, count);
  671. return count;
  672. }
  673. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  674. .attr = {
  675. .name = "dcbx_tlv",
  676. .mode = S_IRUSR,
  677. },
  678. .size = 0,
  679. .read = qla2x00_sysfs_read_dcbx_tlv,
  680. };
  681. static struct sysfs_entry {
  682. char *name;
  683. struct bin_attribute *attr;
  684. int is4GBp_only;
  685. } bin_file_entries[] = {
  686. { "fw_dump", &sysfs_fw_dump_attr, },
  687. { "nvram", &sysfs_nvram_attr, },
  688. { "optrom", &sysfs_optrom_attr, },
  689. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  690. { "vpd", &sysfs_vpd_attr, 1 },
  691. { "sfp", &sysfs_sfp_attr, 1 },
  692. { "reset", &sysfs_reset_attr, },
  693. { "edc", &sysfs_edc_attr, 2 },
  694. { "edc_status", &sysfs_edc_status_attr, 2 },
  695. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  696. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  697. { NULL },
  698. };
  699. void
  700. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  701. {
  702. struct Scsi_Host *host = vha->host;
  703. struct sysfs_entry *iter;
  704. int ret;
  705. for (iter = bin_file_entries; iter->name; iter++) {
  706. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  707. continue;
  708. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  709. continue;
  710. if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
  711. continue;
  712. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  713. iter->attr);
  714. if (ret)
  715. qla_printk(KERN_INFO, vha->hw,
  716. "Unable to create sysfs %s binary attribute "
  717. "(%d).\n", iter->name, ret);
  718. }
  719. }
  720. void
  721. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  722. {
  723. struct Scsi_Host *host = vha->host;
  724. struct sysfs_entry *iter;
  725. struct qla_hw_data *ha = vha->hw;
  726. for (iter = bin_file_entries; iter->name; iter++) {
  727. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  728. continue;
  729. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  730. continue;
  731. if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
  732. continue;
  733. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  734. iter->attr);
  735. }
  736. if (ha->beacon_blink_led == 1)
  737. ha->isp_ops->beacon_off(vha);
  738. }
  739. /* Scsi_Host attributes. */
  740. static ssize_t
  741. qla2x00_drvr_version_show(struct device *dev,
  742. struct device_attribute *attr, char *buf)
  743. {
  744. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  745. }
  746. static ssize_t
  747. qla2x00_fw_version_show(struct device *dev,
  748. struct device_attribute *attr, char *buf)
  749. {
  750. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  751. struct qla_hw_data *ha = vha->hw;
  752. char fw_str[128];
  753. return snprintf(buf, PAGE_SIZE, "%s\n",
  754. ha->isp_ops->fw_version_str(vha, fw_str));
  755. }
  756. static ssize_t
  757. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  758. char *buf)
  759. {
  760. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  761. struct qla_hw_data *ha = vha->hw;
  762. uint32_t sn;
  763. if (IS_FWI2_CAPABLE(ha)) {
  764. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  765. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  766. }
  767. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  768. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  769. sn % 100000);
  770. }
  771. static ssize_t
  772. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  773. char *buf)
  774. {
  775. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  776. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  777. }
  778. static ssize_t
  779. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  780. char *buf)
  781. {
  782. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  783. struct qla_hw_data *ha = vha->hw;
  784. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  785. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  786. ha->product_id[3]);
  787. }
  788. static ssize_t
  789. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  790. char *buf)
  791. {
  792. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  793. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  794. }
  795. static ssize_t
  796. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  797. char *buf)
  798. {
  799. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  800. return snprintf(buf, PAGE_SIZE, "%s\n",
  801. vha->hw->model_desc ? vha->hw->model_desc : "");
  802. }
  803. static ssize_t
  804. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  805. char *buf)
  806. {
  807. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  808. char pci_info[30];
  809. return snprintf(buf, PAGE_SIZE, "%s\n",
  810. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  811. }
  812. static ssize_t
  813. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  814. char *buf)
  815. {
  816. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  817. struct qla_hw_data *ha = vha->hw;
  818. int len = 0;
  819. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  820. atomic_read(&vha->loop_state) == LOOP_DEAD)
  821. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  822. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  823. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  824. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  825. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  826. else {
  827. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  828. switch (ha->current_topology) {
  829. case ISP_CFG_NL:
  830. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  831. break;
  832. case ISP_CFG_FL:
  833. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  834. break;
  835. case ISP_CFG_N:
  836. len += snprintf(buf + len, PAGE_SIZE-len,
  837. "N_Port to N_Port\n");
  838. break;
  839. case ISP_CFG_F:
  840. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  841. break;
  842. default:
  843. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  844. break;
  845. }
  846. }
  847. return len;
  848. }
  849. static ssize_t
  850. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  851. char *buf)
  852. {
  853. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  854. int len = 0;
  855. switch (vha->hw->zio_mode) {
  856. case QLA_ZIO_MODE_6:
  857. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  858. break;
  859. case QLA_ZIO_DISABLED:
  860. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  861. break;
  862. }
  863. return len;
  864. }
  865. static ssize_t
  866. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  867. const char *buf, size_t count)
  868. {
  869. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  870. struct qla_hw_data *ha = vha->hw;
  871. int val = 0;
  872. uint16_t zio_mode;
  873. if (!IS_ZIO_SUPPORTED(ha))
  874. return -ENOTSUPP;
  875. if (sscanf(buf, "%d", &val) != 1)
  876. return -EINVAL;
  877. if (val)
  878. zio_mode = QLA_ZIO_MODE_6;
  879. else
  880. zio_mode = QLA_ZIO_DISABLED;
  881. /* Update per-hba values and queue a reset. */
  882. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  883. ha->zio_mode = zio_mode;
  884. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  885. }
  886. return strlen(buf);
  887. }
  888. static ssize_t
  889. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  890. char *buf)
  891. {
  892. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  893. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  894. }
  895. static ssize_t
  896. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  897. const char *buf, size_t count)
  898. {
  899. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  900. int val = 0;
  901. uint16_t zio_timer;
  902. if (sscanf(buf, "%d", &val) != 1)
  903. return -EINVAL;
  904. if (val > 25500 || val < 100)
  905. return -ERANGE;
  906. zio_timer = (uint16_t)(val / 100);
  907. vha->hw->zio_timer = zio_timer;
  908. return strlen(buf);
  909. }
  910. static ssize_t
  911. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  912. char *buf)
  913. {
  914. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  915. int len = 0;
  916. if (vha->hw->beacon_blink_led)
  917. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  918. else
  919. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  920. return len;
  921. }
  922. static ssize_t
  923. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  924. const char *buf, size_t count)
  925. {
  926. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  927. struct qla_hw_data *ha = vha->hw;
  928. int val = 0;
  929. int rval;
  930. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  931. return -EPERM;
  932. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  933. qla_printk(KERN_WARNING, ha,
  934. "Abort ISP active -- ignoring beacon request.\n");
  935. return -EBUSY;
  936. }
  937. if (sscanf(buf, "%d", &val) != 1)
  938. return -EINVAL;
  939. if (val)
  940. rval = ha->isp_ops->beacon_on(vha);
  941. else
  942. rval = ha->isp_ops->beacon_off(vha);
  943. if (rval != QLA_SUCCESS)
  944. count = 0;
  945. return count;
  946. }
  947. static ssize_t
  948. qla2x00_optrom_bios_version_show(struct device *dev,
  949. struct device_attribute *attr, char *buf)
  950. {
  951. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  952. struct qla_hw_data *ha = vha->hw;
  953. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  954. ha->bios_revision[0]);
  955. }
  956. static ssize_t
  957. qla2x00_optrom_efi_version_show(struct device *dev,
  958. struct device_attribute *attr, char *buf)
  959. {
  960. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  961. struct qla_hw_data *ha = vha->hw;
  962. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  963. ha->efi_revision[0]);
  964. }
  965. static ssize_t
  966. qla2x00_optrom_fcode_version_show(struct device *dev,
  967. struct device_attribute *attr, char *buf)
  968. {
  969. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  970. struct qla_hw_data *ha = vha->hw;
  971. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  972. ha->fcode_revision[0]);
  973. }
  974. static ssize_t
  975. qla2x00_optrom_fw_version_show(struct device *dev,
  976. struct device_attribute *attr, char *buf)
  977. {
  978. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  979. struct qla_hw_data *ha = vha->hw;
  980. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  981. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  982. ha->fw_revision[3]);
  983. }
  984. static ssize_t
  985. qla2x00_total_isp_aborts_show(struct device *dev,
  986. struct device_attribute *attr, char *buf)
  987. {
  988. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  989. struct qla_hw_data *ha = vha->hw;
  990. return snprintf(buf, PAGE_SIZE, "%d\n",
  991. ha->qla_stats.total_isp_aborts);
  992. }
  993. static ssize_t
  994. qla24xx_84xx_fw_version_show(struct device *dev,
  995. struct device_attribute *attr, char *buf)
  996. {
  997. int rval = QLA_SUCCESS;
  998. uint16_t status[2] = {0, 0};
  999. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1000. struct qla_hw_data *ha = vha->hw;
  1001. if (IS_QLA84XX(ha) && ha->cs84xx) {
  1002. if (ha->cs84xx->op_fw_version == 0) {
  1003. rval = qla84xx_verify_chip(vha, status);
  1004. }
  1005. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1006. return snprintf(buf, PAGE_SIZE, "%u\n",
  1007. (uint32_t)ha->cs84xx->op_fw_version);
  1008. }
  1009. return snprintf(buf, PAGE_SIZE, "\n");
  1010. }
  1011. static ssize_t
  1012. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1013. char *buf)
  1014. {
  1015. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1016. struct qla_hw_data *ha = vha->hw;
  1017. if (!IS_QLA81XX(ha))
  1018. return snprintf(buf, PAGE_SIZE, "\n");
  1019. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1020. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1021. ha->mpi_capabilities);
  1022. }
  1023. static ssize_t
  1024. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1025. char *buf)
  1026. {
  1027. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1028. struct qla_hw_data *ha = vha->hw;
  1029. if (!IS_QLA81XX(ha))
  1030. return snprintf(buf, PAGE_SIZE, "\n");
  1031. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1032. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1033. }
  1034. static ssize_t
  1035. qla2x00_flash_block_size_show(struct device *dev,
  1036. struct device_attribute *attr, char *buf)
  1037. {
  1038. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1039. struct qla_hw_data *ha = vha->hw;
  1040. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1041. }
  1042. static ssize_t
  1043. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1044. char *buf)
  1045. {
  1046. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1047. if (!IS_QLA81XX(vha->hw))
  1048. return snprintf(buf, PAGE_SIZE, "\n");
  1049. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1050. }
  1051. static ssize_t
  1052. qla2x00_vn_port_mac_address_show(struct device *dev,
  1053. struct device_attribute *attr, char *buf)
  1054. {
  1055. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1056. if (!IS_QLA81XX(vha->hw))
  1057. return snprintf(buf, PAGE_SIZE, "\n");
  1058. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1059. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1060. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1061. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1062. }
  1063. static ssize_t
  1064. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1065. char *buf)
  1066. {
  1067. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1068. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1069. }
  1070. static ssize_t
  1071. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1072. char *buf)
  1073. {
  1074. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1075. int rval = QLA_FUNCTION_FAILED;
  1076. uint16_t state[5];
  1077. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1078. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  1079. DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n",
  1080. __func__, vha->host_no));
  1081. else if (!vha->hw->flags.eeh_busy)
  1082. rval = qla2x00_get_firmware_state(vha, state);
  1083. if (rval != QLA_SUCCESS)
  1084. memset(state, -1, sizeof(state));
  1085. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1086. state[1], state[2], state[3], state[4]);
  1087. }
  1088. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1089. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1090. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1091. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1092. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1093. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1094. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1095. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1096. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1097. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1098. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1099. qla2x00_zio_timer_store);
  1100. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1101. qla2x00_beacon_store);
  1102. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1103. qla2x00_optrom_bios_version_show, NULL);
  1104. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1105. qla2x00_optrom_efi_version_show, NULL);
  1106. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1107. qla2x00_optrom_fcode_version_show, NULL);
  1108. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1109. NULL);
  1110. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1111. NULL);
  1112. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1113. NULL);
  1114. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1115. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1116. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1117. NULL);
  1118. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1119. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1120. qla2x00_vn_port_mac_address_show, NULL);
  1121. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1122. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1123. struct device_attribute *qla2x00_host_attrs[] = {
  1124. &dev_attr_driver_version,
  1125. &dev_attr_fw_version,
  1126. &dev_attr_serial_num,
  1127. &dev_attr_isp_name,
  1128. &dev_attr_isp_id,
  1129. &dev_attr_model_name,
  1130. &dev_attr_model_desc,
  1131. &dev_attr_pci_info,
  1132. &dev_attr_link_state,
  1133. &dev_attr_zio,
  1134. &dev_attr_zio_timer,
  1135. &dev_attr_beacon,
  1136. &dev_attr_optrom_bios_version,
  1137. &dev_attr_optrom_efi_version,
  1138. &dev_attr_optrom_fcode_version,
  1139. &dev_attr_optrom_fw_version,
  1140. &dev_attr_84xx_fw_version,
  1141. &dev_attr_total_isp_aborts,
  1142. &dev_attr_mpi_version,
  1143. &dev_attr_phy_version,
  1144. &dev_attr_flash_block_size,
  1145. &dev_attr_vlan_id,
  1146. &dev_attr_vn_port_mac_address,
  1147. &dev_attr_fabric_param,
  1148. &dev_attr_fw_state,
  1149. NULL,
  1150. };
  1151. /* Host attributes. */
  1152. static void
  1153. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1154. {
  1155. scsi_qla_host_t *vha = shost_priv(shost);
  1156. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1157. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1158. }
  1159. static void
  1160. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1161. {
  1162. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1163. (shost_priv(shost)))->hw;
  1164. u32 speed = FC_PORTSPEED_UNKNOWN;
  1165. switch (ha->link_data_rate) {
  1166. case PORT_SPEED_1GB:
  1167. speed = FC_PORTSPEED_1GBIT;
  1168. break;
  1169. case PORT_SPEED_2GB:
  1170. speed = FC_PORTSPEED_2GBIT;
  1171. break;
  1172. case PORT_SPEED_4GB:
  1173. speed = FC_PORTSPEED_4GBIT;
  1174. break;
  1175. case PORT_SPEED_8GB:
  1176. speed = FC_PORTSPEED_8GBIT;
  1177. break;
  1178. case PORT_SPEED_10GB:
  1179. speed = FC_PORTSPEED_10GBIT;
  1180. break;
  1181. }
  1182. fc_host_speed(shost) = speed;
  1183. }
  1184. static void
  1185. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1186. {
  1187. scsi_qla_host_t *vha = shost_priv(shost);
  1188. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1189. if (vha->vp_idx) {
  1190. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1191. return;
  1192. }
  1193. switch (vha->hw->current_topology) {
  1194. case ISP_CFG_NL:
  1195. port_type = FC_PORTTYPE_LPORT;
  1196. break;
  1197. case ISP_CFG_FL:
  1198. port_type = FC_PORTTYPE_NLPORT;
  1199. break;
  1200. case ISP_CFG_N:
  1201. port_type = FC_PORTTYPE_PTP;
  1202. break;
  1203. case ISP_CFG_F:
  1204. port_type = FC_PORTTYPE_NPORT;
  1205. break;
  1206. }
  1207. fc_host_port_type(shost) = port_type;
  1208. }
  1209. static void
  1210. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1211. {
  1212. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1213. scsi_qla_host_t *vha = shost_priv(host);
  1214. fc_port_t *fcport;
  1215. u64 node_name = 0;
  1216. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1217. if (fcport->rport &&
  1218. starget->id == fcport->rport->scsi_target_id) {
  1219. node_name = wwn_to_u64(fcport->node_name);
  1220. break;
  1221. }
  1222. }
  1223. fc_starget_node_name(starget) = node_name;
  1224. }
  1225. static void
  1226. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1227. {
  1228. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1229. scsi_qla_host_t *vha = shost_priv(host);
  1230. fc_port_t *fcport;
  1231. u64 port_name = 0;
  1232. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1233. if (fcport->rport &&
  1234. starget->id == fcport->rport->scsi_target_id) {
  1235. port_name = wwn_to_u64(fcport->port_name);
  1236. break;
  1237. }
  1238. }
  1239. fc_starget_port_name(starget) = port_name;
  1240. }
  1241. static void
  1242. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1243. {
  1244. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1245. scsi_qla_host_t *vha = shost_priv(host);
  1246. fc_port_t *fcport;
  1247. uint32_t port_id = ~0U;
  1248. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1249. if (fcport->rport &&
  1250. starget->id == fcport->rport->scsi_target_id) {
  1251. port_id = fcport->d_id.b.domain << 16 |
  1252. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1253. break;
  1254. }
  1255. }
  1256. fc_starget_port_id(starget) = port_id;
  1257. }
  1258. static void
  1259. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1260. {
  1261. if (timeout)
  1262. rport->dev_loss_tmo = timeout;
  1263. else
  1264. rport->dev_loss_tmo = 1;
  1265. }
  1266. static void
  1267. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1268. {
  1269. struct Scsi_Host *host = rport_to_shost(rport);
  1270. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1271. if (!fcport)
  1272. return;
  1273. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1274. return;
  1275. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1276. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1277. return;
  1278. }
  1279. /*
  1280. * Transport has effectively 'deleted' the rport, clear
  1281. * all local references.
  1282. */
  1283. spin_lock_irq(host->host_lock);
  1284. fcport->rport = NULL;
  1285. *((fc_port_t **)rport->dd_data) = NULL;
  1286. spin_unlock_irq(host->host_lock);
  1287. }
  1288. static void
  1289. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1290. {
  1291. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1292. if (!fcport)
  1293. return;
  1294. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1295. return;
  1296. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1297. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1298. return;
  1299. }
  1300. /*
  1301. * At this point all fcport's software-states are cleared. Perform any
  1302. * final cleanup of firmware resources (PCBs and XCBs).
  1303. */
  1304. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1305. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1306. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1307. fcport->loop_id, fcport->d_id.b.domain,
  1308. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1309. }
  1310. static int
  1311. qla2x00_issue_lip(struct Scsi_Host *shost)
  1312. {
  1313. scsi_qla_host_t *vha = shost_priv(shost);
  1314. qla2x00_loop_reset(vha);
  1315. return 0;
  1316. }
  1317. static struct fc_host_statistics *
  1318. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1319. {
  1320. scsi_qla_host_t *vha = shost_priv(shost);
  1321. struct qla_hw_data *ha = vha->hw;
  1322. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1323. int rval;
  1324. struct link_statistics *stats;
  1325. dma_addr_t stats_dma;
  1326. struct fc_host_statistics *pfc_host_stat;
  1327. pfc_host_stat = &ha->fc_host_stat;
  1328. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1329. if (test_bit(UNLOADING, &vha->dpc_flags))
  1330. goto done;
  1331. if (unlikely(pci_channel_offline(ha->pdev)))
  1332. goto done;
  1333. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1334. if (stats == NULL) {
  1335. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1336. __func__, base_vha->host_no));
  1337. goto done;
  1338. }
  1339. memset(stats, 0, DMA_POOL_SIZE);
  1340. rval = QLA_FUNCTION_FAILED;
  1341. if (IS_FWI2_CAPABLE(ha)) {
  1342. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1343. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1344. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1345. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1346. !ha->dpc_active) {
  1347. /* Must be in a 'READY' state for statistics retrieval. */
  1348. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1349. stats, stats_dma);
  1350. }
  1351. if (rval != QLA_SUCCESS)
  1352. goto done_free;
  1353. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1354. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1355. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1356. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1357. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1358. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1359. if (IS_FWI2_CAPABLE(ha)) {
  1360. pfc_host_stat->lip_count = stats->lip_cnt;
  1361. pfc_host_stat->tx_frames = stats->tx_frames;
  1362. pfc_host_stat->rx_frames = stats->rx_frames;
  1363. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1364. pfc_host_stat->nos_count = stats->nos_rcvd;
  1365. }
  1366. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1367. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1368. done_free:
  1369. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1370. done:
  1371. return pfc_host_stat;
  1372. }
  1373. static void
  1374. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1375. {
  1376. scsi_qla_host_t *vha = shost_priv(shost);
  1377. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1378. }
  1379. static void
  1380. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1381. {
  1382. scsi_qla_host_t *vha = shost_priv(shost);
  1383. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1384. }
  1385. static void
  1386. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1387. {
  1388. scsi_qla_host_t *vha = shost_priv(shost);
  1389. u64 node_name;
  1390. if (vha->device_flags & SWITCH_FOUND)
  1391. node_name = wwn_to_u64(vha->fabric_node_name);
  1392. else
  1393. node_name = wwn_to_u64(vha->node_name);
  1394. fc_host_fabric_name(shost) = node_name;
  1395. }
  1396. static void
  1397. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1398. {
  1399. scsi_qla_host_t *vha = shost_priv(shost);
  1400. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1401. if (!base_vha->flags.online)
  1402. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1403. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1404. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1405. else
  1406. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1407. }
  1408. static int
  1409. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1410. {
  1411. int ret = 0;
  1412. uint8_t qos = 0;
  1413. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1414. scsi_qla_host_t *vha = NULL;
  1415. struct qla_hw_data *ha = base_vha->hw;
  1416. uint16_t options = 0;
  1417. int cnt;
  1418. struct req_que *req = ha->req_q_map[0];
  1419. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1420. if (ret) {
  1421. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1422. "status %x\n", ret));
  1423. return (ret);
  1424. }
  1425. vha = qla24xx_create_vhost(fc_vport);
  1426. if (vha == NULL) {
  1427. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1428. vha));
  1429. return FC_VPORT_FAILED;
  1430. }
  1431. if (disable) {
  1432. atomic_set(&vha->vp_state, VP_OFFLINE);
  1433. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1434. } else
  1435. atomic_set(&vha->vp_state, VP_FAILED);
  1436. /* ready to create vport */
  1437. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1438. vha->vp_idx);
  1439. /* initialized vport states */
  1440. atomic_set(&vha->loop_state, LOOP_DOWN);
  1441. vha->vp_err_state= VP_ERR_PORTDWN;
  1442. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1443. /* Check if physical ha port is Up */
  1444. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1445. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1446. /* Don't retry or attempt login of this virtual port */
  1447. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1448. base_vha->host_no));
  1449. atomic_set(&vha->loop_state, LOOP_DEAD);
  1450. if (!disable)
  1451. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1452. }
  1453. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1454. &ha->pdev->dev)) {
  1455. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1456. vha->host_no, vha->vp_idx));
  1457. goto vport_create_failed_2;
  1458. }
  1459. /* initialize attributes */
  1460. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1461. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1462. fc_host_supported_classes(vha->host) =
  1463. fc_host_supported_classes(base_vha->host);
  1464. fc_host_supported_speeds(vha->host) =
  1465. fc_host_supported_speeds(base_vha->host);
  1466. qla24xx_vport_disable(fc_vport, disable);
  1467. if (ha->flags.cpu_affinity_enabled) {
  1468. req = ha->req_q_map[1];
  1469. goto vport_queue;
  1470. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1471. goto vport_queue;
  1472. /* Create a request queue in QoS mode for the vport */
  1473. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1474. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1475. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1476. 8) == 0) {
  1477. qos = ha->npiv_info[cnt].q_qos;
  1478. break;
  1479. }
  1480. }
  1481. if (qos) {
  1482. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1483. qos);
  1484. if (!ret)
  1485. qla_printk(KERN_WARNING, ha,
  1486. "Can't create request queue for vp_idx:%d\n",
  1487. vha->vp_idx);
  1488. else {
  1489. DEBUG2(qla_printk(KERN_INFO, ha,
  1490. "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
  1491. ret, qos, vha->vp_idx));
  1492. req = ha->req_q_map[ret];
  1493. }
  1494. }
  1495. vport_queue:
  1496. vha->req = req;
  1497. return 0;
  1498. vport_create_failed_2:
  1499. qla24xx_disable_vp(vha);
  1500. qla24xx_deallocate_vp_id(vha);
  1501. scsi_host_put(vha->host);
  1502. return FC_VPORT_FAILED;
  1503. }
  1504. static int
  1505. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1506. {
  1507. scsi_qla_host_t *vha = fc_vport->dd_data;
  1508. fc_port_t *fcport, *tfcport;
  1509. struct qla_hw_data *ha = vha->hw;
  1510. uint16_t id = vha->vp_idx;
  1511. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1512. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1513. msleep(1000);
  1514. qla24xx_disable_vp(vha);
  1515. fc_remove_host(vha->host);
  1516. scsi_remove_host(vha->host);
  1517. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1518. list_del(&fcport->list);
  1519. kfree(fcport);
  1520. fcport = NULL;
  1521. }
  1522. qla24xx_deallocate_vp_id(vha);
  1523. mutex_lock(&ha->vport_lock);
  1524. ha->cur_vport_count--;
  1525. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1526. mutex_unlock(&ha->vport_lock);
  1527. if (vha->timer_active) {
  1528. qla2x00_vp_stop_timer(vha);
  1529. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1530. "has stopped\n",
  1531. vha->host_no, vha->vp_idx, vha));
  1532. }
  1533. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1534. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1535. qla_printk(KERN_WARNING, ha,
  1536. "Queue delete failed.\n");
  1537. }
  1538. scsi_host_put(vha->host);
  1539. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1540. return 0;
  1541. }
  1542. static int
  1543. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1544. {
  1545. scsi_qla_host_t *vha = fc_vport->dd_data;
  1546. if (disable)
  1547. qla24xx_disable_vp(vha);
  1548. else
  1549. qla24xx_enable_vp(vha);
  1550. return 0;
  1551. }
  1552. /* BSG support for ELS/CT pass through */
  1553. inline srb_t *
  1554. qla2x00_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size)
  1555. {
  1556. srb_t *sp;
  1557. struct qla_hw_data *ha = vha->hw;
  1558. struct srb_bsg_ctx *ctx;
  1559. sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
  1560. if (!sp)
  1561. goto done;
  1562. ctx = kzalloc(size, GFP_KERNEL);
  1563. if (!ctx) {
  1564. mempool_free(sp, ha->srb_mempool);
  1565. goto done;
  1566. }
  1567. memset(sp, 0, sizeof(*sp));
  1568. sp->fcport = fcport;
  1569. sp->ctx = ctx;
  1570. done:
  1571. return sp;
  1572. }
  1573. static int
  1574. qla2x00_process_els(struct fc_bsg_job *bsg_job)
  1575. {
  1576. struct fc_rport *rport;
  1577. fc_port_t *fcport;
  1578. struct Scsi_Host *host;
  1579. scsi_qla_host_t *vha;
  1580. struct qla_hw_data *ha;
  1581. srb_t *sp;
  1582. const char *type;
  1583. int req_sg_cnt, rsp_sg_cnt;
  1584. int rval = (DRIVER_ERROR << 16);
  1585. uint16_t nextlid = 0;
  1586. struct srb_bsg *els;
  1587. /* Multiple SG's are not supported for ELS requests */
  1588. if (bsg_job->request_payload.sg_cnt > 1 ||
  1589. bsg_job->reply_payload.sg_cnt > 1) {
  1590. DEBUG2(printk(KERN_INFO
  1591. "multiple SG's are not supported for ELS requests"
  1592. " [request_sg_cnt: %x reply_sg_cnt: %x]\n",
  1593. bsg_job->request_payload.sg_cnt,
  1594. bsg_job->reply_payload.sg_cnt));
  1595. rval = -EPERM;
  1596. goto done;
  1597. }
  1598. /* ELS request for rport */
  1599. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  1600. rport = bsg_job->rport;
  1601. fcport = *(fc_port_t **) rport->dd_data;
  1602. host = rport_to_shost(rport);
  1603. vha = shost_priv(host);
  1604. ha = vha->hw;
  1605. type = "FC_BSG_RPT_ELS";
  1606. /* make sure the rport is logged in,
  1607. * if not perform fabric login
  1608. */
  1609. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  1610. DEBUG2(qla_printk(KERN_WARNING, ha,
  1611. "failed to login port %06X for ELS passthru\n",
  1612. fcport->d_id.b24));
  1613. rval = -EIO;
  1614. goto done;
  1615. }
  1616. } else {
  1617. host = bsg_job->shost;
  1618. vha = shost_priv(host);
  1619. ha = vha->hw;
  1620. type = "FC_BSG_HST_ELS_NOLOGIN";
  1621. /* Allocate a dummy fcport structure, since functions
  1622. * preparing the IOCB and mailbox command retrieves port
  1623. * specific information from fcport structure. For Host based
  1624. * ELS commands there will be no fcport structure allocated
  1625. */
  1626. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1627. if (!fcport) {
  1628. rval = -ENOMEM;
  1629. goto done;
  1630. }
  1631. /* Initialize all required fields of fcport */
  1632. fcport->vha = vha;
  1633. fcport->vp_idx = vha->vp_idx;
  1634. fcport->d_id.b.al_pa =
  1635. bsg_job->request->rqst_data.h_els.port_id[0];
  1636. fcport->d_id.b.area =
  1637. bsg_job->request->rqst_data.h_els.port_id[1];
  1638. fcport->d_id.b.domain =
  1639. bsg_job->request->rqst_data.h_els.port_id[2];
  1640. fcport->loop_id =
  1641. (fcport->d_id.b.al_pa == 0xFD) ?
  1642. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  1643. }
  1644. if (!vha->flags.online) {
  1645. DEBUG2(qla_printk(KERN_WARNING, ha,
  1646. "host not online\n"));
  1647. rval = -EIO;
  1648. goto done;
  1649. }
  1650. req_sg_cnt =
  1651. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1652. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1653. if (!req_sg_cnt) {
  1654. rval = -ENOMEM;
  1655. goto done_free_fcport;
  1656. }
  1657. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1658. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1659. if (!rsp_sg_cnt) {
  1660. rval = -ENOMEM;
  1661. goto done_free_fcport;
  1662. }
  1663. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1664. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1665. {
  1666. DEBUG2(printk(KERN_INFO
  1667. "dma mapping resulted in different sg counts \
  1668. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1669. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1670. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1671. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1672. rval = -EAGAIN;
  1673. goto done_unmap_sg;
  1674. }
  1675. /* Alloc SRB structure */
  1676. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1677. if (!sp) {
  1678. rval = -ENOMEM;
  1679. goto done_unmap_sg;
  1680. }
  1681. els = sp->ctx;
  1682. els->ctx.type =
  1683. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  1684. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  1685. els->bsg_job = bsg_job;
  1686. DEBUG2(qla_printk(KERN_INFO, ha,
  1687. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1688. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1689. bsg_job->request->rqst_data.h_els.command_code,
  1690. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1691. fcport->d_id.b.al_pa));
  1692. rval = qla2x00_start_sp(sp);
  1693. if (rval != QLA_SUCCESS) {
  1694. kfree(sp->ctx);
  1695. mempool_free(sp, ha->srb_mempool);
  1696. rval = -EIO;
  1697. goto done_unmap_sg;
  1698. }
  1699. return rval;
  1700. done_unmap_sg:
  1701. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1702. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1703. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1704. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1705. goto done_free_fcport;
  1706. done_free_fcport:
  1707. if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
  1708. kfree(fcport);
  1709. done:
  1710. return rval;
  1711. }
  1712. static int
  1713. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  1714. {
  1715. srb_t *sp;
  1716. struct Scsi_Host *host = bsg_job->shost;
  1717. scsi_qla_host_t *vha = shost_priv(host);
  1718. struct qla_hw_data *ha = vha->hw;
  1719. int rval = (DRIVER_ERROR << 16);
  1720. int req_sg_cnt, rsp_sg_cnt;
  1721. uint16_t loop_id;
  1722. struct fc_port *fcport;
  1723. char *type = "FC_BSG_HST_CT";
  1724. struct srb_bsg *ct;
  1725. /* pass through is supported only for ISP 4Gb or higher */
  1726. if (!IS_FWI2_CAPABLE(ha)) {
  1727. DEBUG2(qla_printk(KERN_INFO, ha,
  1728. "scsi(%ld):Firmware is not capable to support FC "
  1729. "CT pass thru\n", vha->host_no));
  1730. rval = -EPERM;
  1731. goto done;
  1732. }
  1733. req_sg_cnt =
  1734. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1735. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1736. if (!req_sg_cnt) {
  1737. rval = -ENOMEM;
  1738. goto done;
  1739. }
  1740. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1741. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1742. if (!rsp_sg_cnt) {
  1743. rval = -ENOMEM;
  1744. goto done;
  1745. }
  1746. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1747. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1748. {
  1749. DEBUG2(qla_printk(KERN_WARNING, ha,
  1750. "dma mapping resulted in different sg counts \
  1751. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1752. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1753. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1754. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1755. rval = -EAGAIN;
  1756. goto done_unmap_sg;
  1757. }
  1758. if (!vha->flags.online) {
  1759. DEBUG2(qla_printk(KERN_WARNING, ha,
  1760. "host not online\n"));
  1761. rval = -EIO;
  1762. goto done_unmap_sg;
  1763. }
  1764. loop_id =
  1765. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  1766. >> 24;
  1767. switch (loop_id) {
  1768. case 0xFC:
  1769. loop_id = cpu_to_le16(NPH_SNS);
  1770. break;
  1771. case 0xFA:
  1772. loop_id = vha->mgmt_svr_loop_id;
  1773. break;
  1774. default:
  1775. DEBUG2(qla_printk(KERN_INFO, ha,
  1776. "Unknown loop id: %x\n", loop_id));
  1777. rval = -EINVAL;
  1778. goto done_unmap_sg;
  1779. }
  1780. /* Allocate a dummy fcport structure, since functions preparing the
  1781. * IOCB and mailbox command retrieves port specific information
  1782. * from fcport structure. For Host based ELS commands there will be
  1783. * no fcport structure allocated
  1784. */
  1785. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1786. if (!fcport)
  1787. {
  1788. rval = -ENOMEM;
  1789. goto done_unmap_sg;
  1790. }
  1791. /* Initialize all required fields of fcport */
  1792. fcport->vha = vha;
  1793. fcport->vp_idx = vha->vp_idx;
  1794. fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
  1795. fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
  1796. fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
  1797. fcport->loop_id = loop_id;
  1798. /* Alloc SRB structure */
  1799. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1800. if (!sp) {
  1801. rval = -ENOMEM;
  1802. goto done_free_fcport;
  1803. }
  1804. ct = sp->ctx;
  1805. ct->ctx.type = SRB_CT_CMD;
  1806. ct->bsg_job = bsg_job;
  1807. DEBUG2(qla_printk(KERN_INFO, ha,
  1808. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1809. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1810. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  1811. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1812. fcport->d_id.b.al_pa));
  1813. rval = qla2x00_start_sp(sp);
  1814. if (rval != QLA_SUCCESS) {
  1815. kfree(sp->ctx);
  1816. mempool_free(sp, ha->srb_mempool);
  1817. rval = -EIO;
  1818. goto done_free_fcport;
  1819. }
  1820. return rval;
  1821. done_free_fcport:
  1822. kfree(fcport);
  1823. done_unmap_sg:
  1824. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1825. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1826. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1827. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1828. done:
  1829. return rval;
  1830. }
  1831. static int
  1832. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1833. {
  1834. struct Scsi_Host *host = bsg_job->shost;
  1835. scsi_qla_host_t *vha = shost_priv(host);
  1836. struct qla_hw_data *ha = vha->hw;
  1837. int rval;
  1838. uint8_t command_sent;
  1839. uint32_t vendor_cmd;
  1840. char *type;
  1841. struct msg_echo_lb elreq;
  1842. uint16_t response[MAILBOX_REGISTER_COUNT];
  1843. uint8_t* fw_sts_ptr;
  1844. uint8_t *req_data;
  1845. dma_addr_t req_data_dma;
  1846. uint32_t req_data_len;
  1847. uint8_t *rsp_data;
  1848. dma_addr_t rsp_data_dma;
  1849. uint32_t rsp_data_len;
  1850. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  1851. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1852. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  1853. rval = -EBUSY;
  1854. goto done;
  1855. }
  1856. if (!vha->flags.online) {
  1857. DEBUG2(qla_printk(KERN_WARNING, ha,
  1858. "host not online\n"));
  1859. rval = -EIO;
  1860. goto done;
  1861. }
  1862. elreq.req_sg_cnt =
  1863. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1864. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1865. if (!elreq.req_sg_cnt) {
  1866. rval = -ENOMEM;
  1867. goto done;
  1868. }
  1869. elreq.rsp_sg_cnt =
  1870. dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1871. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1872. if (!elreq.rsp_sg_cnt) {
  1873. rval = -ENOMEM;
  1874. goto done;
  1875. }
  1876. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1877. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1878. {
  1879. DEBUG2(printk(KERN_INFO
  1880. "dma mapping resulted in different sg counts \
  1881. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1882. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1883. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  1884. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
  1885. rval = -EAGAIN;
  1886. goto done_unmap_sg;
  1887. }
  1888. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  1889. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  1890. &req_data_dma, GFP_KERNEL);
  1891. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  1892. &rsp_data_dma, GFP_KERNEL);
  1893. /* Copy the request buffer in req_data now */
  1894. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1895. bsg_job->request_payload.sg_cnt, req_data,
  1896. req_data_len);
  1897. elreq.send_dma = req_data_dma;
  1898. elreq.rcv_dma = rsp_data_dma;
  1899. elreq.transfer_size = req_data_len;
  1900. /* Vendor cmd : loopback or ECHO diagnostic
  1901. * Options:
  1902. * Loopback : Either internal or external loopback
  1903. * ECHO: ECHO ELS or Vendor specific FC4 link data
  1904. */
  1905. vendor_cmd = bsg_job->request->rqst_data.h_vendor.vendor_cmd[0];
  1906. elreq.options =
  1907. *(((uint32_t *)bsg_job->request->rqst_data.h_vendor.vendor_cmd)
  1908. + 1);
  1909. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1910. case QL_VND_LOOPBACK:
  1911. if (ha->current_topology != ISP_CFG_F) {
  1912. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  1913. DEBUG2(qla_printk(KERN_INFO, ha,
  1914. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1915. vha->host_no, type, vendor_cmd, elreq.options));
  1916. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  1917. rval = qla2x00_loopback_test(vha, &elreq, response);
  1918. if (IS_QLA81XX(ha)) {
  1919. if (response[0] == MBS_COMMAND_ERROR && response[1] == MBS_LB_RESET) {
  1920. DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
  1921. "ISP\n", __func__, vha->host_no));
  1922. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1923. qla2xxx_wake_dpc(vha);
  1924. }
  1925. }
  1926. } else {
  1927. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  1928. DEBUG2(qla_printk(KERN_INFO, ha,
  1929. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1930. vha->host_no, type, vendor_cmd, elreq.options));
  1931. command_sent = INT_DEF_LB_ECHO_CMD;
  1932. rval = qla2x00_echo_test(vha, &elreq, response);
  1933. }
  1934. break;
  1935. case QLA84_RESET:
  1936. if (!IS_QLA84XX(vha->hw)) {
  1937. rval = -EINVAL;
  1938. DEBUG16(printk(
  1939. "%s(%ld): 8xxx exiting.\n",
  1940. __func__, vha->host_no));
  1941. return rval;
  1942. }
  1943. rval = qla84xx_reset(vha, &elreq, bsg_job);
  1944. break;
  1945. case QLA84_MGMT_CMD:
  1946. if (!IS_QLA84XX(vha->hw)) {
  1947. rval = -EINVAL;
  1948. DEBUG16(printk(
  1949. "%s(%ld): 8xxx exiting.\n",
  1950. __func__, vha->host_no));
  1951. return rval;
  1952. }
  1953. rval = qla84xx_mgmt_cmd(vha, &elreq, bsg_job);
  1954. break;
  1955. default:
  1956. rval = -ENOSYS;
  1957. }
  1958. if (rval != QLA_SUCCESS) {
  1959. DEBUG2(qla_printk(KERN_WARNING, ha,
  1960. "scsi(%ld) Vendor request %s failed\n", vha->host_no, type));
  1961. rval = 0;
  1962. bsg_job->reply->result = (DID_ERROR << 16);
  1963. bsg_job->reply->reply_payload_rcv_len = 0;
  1964. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1965. memcpy( fw_sts_ptr, response, sizeof(response));
  1966. fw_sts_ptr += sizeof(response);
  1967. *fw_sts_ptr = command_sent;
  1968. } else {
  1969. DEBUG2(qla_printk(KERN_WARNING, ha,
  1970. "scsi(%ld) Vendor request %s completed\n", vha->host_no, type));
  1971. rval = bsg_job->reply->result = 0;
  1972. bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(response) + sizeof(uint8_t);
  1973. bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
  1974. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1975. memcpy(fw_sts_ptr, response, sizeof(response));
  1976. fw_sts_ptr += sizeof(response);
  1977. *fw_sts_ptr = command_sent;
  1978. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1979. bsg_job->reply_payload.sg_cnt, rsp_data,
  1980. rsp_data_len);
  1981. }
  1982. bsg_job->job_done(bsg_job);
  1983. done_unmap_sg:
  1984. if(req_data)
  1985. dma_free_coherent(&ha->pdev->dev, req_data_len,
  1986. req_data, req_data_dma);
  1987. dma_unmap_sg(&ha->pdev->dev,
  1988. bsg_job->request_payload.sg_list,
  1989. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1990. dma_unmap_sg(&ha->pdev->dev,
  1991. bsg_job->reply_payload.sg_list,
  1992. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1993. done:
  1994. return rval;
  1995. }
  1996. static int
  1997. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  1998. {
  1999. int ret = -EINVAL;
  2000. switch (bsg_job->request->msgcode) {
  2001. case FC_BSG_RPT_ELS:
  2002. case FC_BSG_HST_ELS_NOLOGIN:
  2003. ret = qla2x00_process_els(bsg_job);
  2004. break;
  2005. case FC_BSG_HST_CT:
  2006. ret = qla2x00_process_ct(bsg_job);
  2007. break;
  2008. case FC_BSG_HST_VENDOR:
  2009. ret = qla2x00_process_vendor_specific(bsg_job);
  2010. break;
  2011. case FC_BSG_HST_ADD_RPORT:
  2012. case FC_BSG_HST_DEL_RPORT:
  2013. case FC_BSG_RPT_CT:
  2014. default:
  2015. DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
  2016. break;
  2017. }
  2018. return ret;
  2019. }
  2020. static int
  2021. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  2022. {
  2023. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  2024. struct qla_hw_data *ha = vha->hw;
  2025. srb_t *sp;
  2026. int cnt, que;
  2027. unsigned long flags;
  2028. struct req_que *req;
  2029. struct srb_bsg *sp_bsg;
  2030. /* find the bsg job from the active list of commands */
  2031. spin_lock_irqsave(&ha->hardware_lock, flags);
  2032. for (que = 0; que < ha->max_req_queues; que++) {
  2033. req = ha->req_q_map[que];
  2034. if (!req)
  2035. continue;
  2036. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++ ) {
  2037. sp = req->outstanding_cmds[cnt];
  2038. if (sp) {
  2039. sp_bsg = (struct srb_bsg*)sp->ctx;
  2040. if (((sp_bsg->ctx.type == SRB_CT_CMD) ||
  2041. (sp_bsg->ctx.type == SRB_ELS_CMD_RPT)
  2042. || ( sp_bsg->ctx.type == SRB_ELS_CMD_HST)) &&
  2043. (sp_bsg->bsg_job == bsg_job)) {
  2044. if (ha->isp_ops->abort_command(sp)) {
  2045. DEBUG2(qla_printk(KERN_INFO, ha,
  2046. "scsi(%ld): mbx abort_command failed\n", vha->host_no));
  2047. bsg_job->req->errors = bsg_job->reply->result = -EIO;
  2048. } else {
  2049. DEBUG2(qla_printk(KERN_INFO, ha,
  2050. "scsi(%ld): mbx abort_command success\n", vha->host_no));
  2051. bsg_job->req->errors = bsg_job->reply->result = 0;
  2052. }
  2053. goto done;
  2054. }
  2055. }
  2056. }
  2057. }
  2058. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2059. DEBUG2(qla_printk(KERN_INFO, ha,
  2060. "scsi(%ld) SRB not found to abort\n", vha->host_no));
  2061. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  2062. return 0;
  2063. done:
  2064. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2065. if (bsg_job->request->msgcode == FC_BSG_HST_CT)
  2066. kfree(sp->fcport);
  2067. kfree(sp->ctx);
  2068. mempool_free(sp, ha->srb_mempool);
  2069. return 0;
  2070. }
  2071. struct fc_function_template qla2xxx_transport_functions = {
  2072. .show_host_node_name = 1,
  2073. .show_host_port_name = 1,
  2074. .show_host_supported_classes = 1,
  2075. .show_host_supported_speeds = 1,
  2076. .get_host_port_id = qla2x00_get_host_port_id,
  2077. .show_host_port_id = 1,
  2078. .get_host_speed = qla2x00_get_host_speed,
  2079. .show_host_speed = 1,
  2080. .get_host_port_type = qla2x00_get_host_port_type,
  2081. .show_host_port_type = 1,
  2082. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2083. .show_host_symbolic_name = 1,
  2084. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2085. .show_host_system_hostname = 1,
  2086. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2087. .show_host_fabric_name = 1,
  2088. .get_host_port_state = qla2x00_get_host_port_state,
  2089. .show_host_port_state = 1,
  2090. .dd_fcrport_size = sizeof(struct fc_port *),
  2091. .show_rport_supported_classes = 1,
  2092. .get_starget_node_name = qla2x00_get_starget_node_name,
  2093. .show_starget_node_name = 1,
  2094. .get_starget_port_name = qla2x00_get_starget_port_name,
  2095. .show_starget_port_name = 1,
  2096. .get_starget_port_id = qla2x00_get_starget_port_id,
  2097. .show_starget_port_id = 1,
  2098. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2099. .show_rport_dev_loss_tmo = 1,
  2100. .issue_fc_host_lip = qla2x00_issue_lip,
  2101. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2102. .terminate_rport_io = qla2x00_terminate_rport_io,
  2103. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2104. .vport_create = qla24xx_vport_create,
  2105. .vport_disable = qla24xx_vport_disable,
  2106. .vport_delete = qla24xx_vport_delete,
  2107. .bsg_request = qla24xx_bsg_request,
  2108. .bsg_timeout = qla24xx_bsg_timeout,
  2109. };
  2110. struct fc_function_template qla2xxx_transport_vport_functions = {
  2111. .show_host_node_name = 1,
  2112. .show_host_port_name = 1,
  2113. .show_host_supported_classes = 1,
  2114. .get_host_port_id = qla2x00_get_host_port_id,
  2115. .show_host_port_id = 1,
  2116. .get_host_speed = qla2x00_get_host_speed,
  2117. .show_host_speed = 1,
  2118. .get_host_port_type = qla2x00_get_host_port_type,
  2119. .show_host_port_type = 1,
  2120. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2121. .show_host_symbolic_name = 1,
  2122. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2123. .show_host_system_hostname = 1,
  2124. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2125. .show_host_fabric_name = 1,
  2126. .get_host_port_state = qla2x00_get_host_port_state,
  2127. .show_host_port_state = 1,
  2128. .dd_fcrport_size = sizeof(struct fc_port *),
  2129. .show_rport_supported_classes = 1,
  2130. .get_starget_node_name = qla2x00_get_starget_node_name,
  2131. .show_starget_node_name = 1,
  2132. .get_starget_port_name = qla2x00_get_starget_port_name,
  2133. .show_starget_port_name = 1,
  2134. .get_starget_port_id = qla2x00_get_starget_port_id,
  2135. .show_starget_port_id = 1,
  2136. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2137. .show_rport_dev_loss_tmo = 1,
  2138. .issue_fc_host_lip = qla2x00_issue_lip,
  2139. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2140. .terminate_rport_io = qla2x00_terminate_rport_io,
  2141. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2142. .bsg_request = qla24xx_bsg_request,
  2143. .bsg_timeout = qla24xx_bsg_timeout,
  2144. };
  2145. void
  2146. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  2147. {
  2148. struct qla_hw_data *ha = vha->hw;
  2149. u32 speed = FC_PORTSPEED_UNKNOWN;
  2150. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  2151. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  2152. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  2153. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  2154. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  2155. if (IS_QLA81XX(ha))
  2156. speed = FC_PORTSPEED_10GBIT;
  2157. else if (IS_QLA25XX(ha))
  2158. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  2159. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2160. else if (IS_QLA24XX_TYPE(ha))
  2161. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  2162. FC_PORTSPEED_1GBIT;
  2163. else if (IS_QLA23XX(ha))
  2164. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2165. else
  2166. speed = FC_PORTSPEED_1GBIT;
  2167. fc_host_supported_speeds(vha->host) = speed;
  2168. }
  2169. static int
  2170. qla84xx_reset(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2171. {
  2172. int ret = 0;
  2173. int cmd;
  2174. uint16_t cmd_status;
  2175. DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2176. cmd = (*((bsg_job->request->rqst_data.h_vendor.vendor_cmd) + 2))
  2177. == A84_RESET_FLAG_ENABLE_DIAG_FW ?
  2178. A84_ISSUE_RESET_DIAG_FW : A84_ISSUE_RESET_OP_FW;
  2179. ret = qla84xx_reset_chip(ha, cmd == A84_ISSUE_RESET_DIAG_FW,
  2180. &cmd_status);
  2181. return ret;
  2182. }
  2183. static int
  2184. qla84xx_mgmt_cmd(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2185. {
  2186. struct access_chip_84xx *mn;
  2187. dma_addr_t mn_dma, mgmt_dma;
  2188. void *mgmt_b = NULL;
  2189. int ret = 0;
  2190. int rsp_hdr_len, len = 0;
  2191. struct qla84_msg_mgmt *ql84_mgmt;
  2192. ql84_mgmt = (struct qla84_msg_mgmt *) vmalloc(sizeof(struct qla84_msg_mgmt));
  2193. ql84_mgmt->cmd =
  2194. *((uint16_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 2));
  2195. ql84_mgmt->mgmtp.u.mem.start_addr =
  2196. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 3));
  2197. ql84_mgmt->len =
  2198. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 4));
  2199. ql84_mgmt->mgmtp.u.config.id =
  2200. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 5));
  2201. ql84_mgmt->mgmtp.u.config.param0 =
  2202. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 6));
  2203. ql84_mgmt->mgmtp.u.config.param1 =
  2204. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 7));
  2205. ql84_mgmt->mgmtp.u.info.type =
  2206. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 8));
  2207. ql84_mgmt->mgmtp.u.info.context =
  2208. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 9));
  2209. rsp_hdr_len = bsg_job->request_payload.payload_len;
  2210. mn = dma_pool_alloc(ha->hw->s_dma_pool, GFP_KERNEL, &mn_dma);
  2211. if (mn == NULL) {
  2212. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
  2213. "failed%lu\n", __func__, ha->host_no));
  2214. return -ENOMEM;
  2215. }
  2216. memset(mn, 0, sizeof (struct access_chip_84xx));
  2217. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  2218. mn->entry_count = 1;
  2219. switch (ql84_mgmt->cmd) {
  2220. case QLA84_MGMT_READ_MEM:
  2221. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  2222. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2223. break;
  2224. case QLA84_MGMT_WRITE_MEM:
  2225. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  2226. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2227. break;
  2228. case QLA84_MGMT_CHNG_CONFIG:
  2229. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  2230. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.id);
  2231. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param0);
  2232. mn->parameter3 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param1);
  2233. break;
  2234. case QLA84_MGMT_GET_INFO:
  2235. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  2236. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.type);
  2237. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.context);
  2238. break;
  2239. default:
  2240. ret = -EIO;
  2241. goto exit_mgmt0;
  2242. }
  2243. if ((len == ql84_mgmt->len) &&
  2244. ql84_mgmt->cmd != QLA84_MGMT_CHNG_CONFIG) {
  2245. mgmt_b = dma_alloc_coherent(&ha->hw->pdev->dev, len,
  2246. &mgmt_dma, GFP_KERNEL);
  2247. if (mgmt_b == NULL) {
  2248. DEBUG2(printk(KERN_ERR "%s: dma alloc mgmt_b "
  2249. "failed%lu\n", __func__, ha->host_no));
  2250. ret = -ENOMEM;
  2251. goto exit_mgmt0;
  2252. }
  2253. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->len);
  2254. mn->dseg_count = cpu_to_le16(1);
  2255. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  2256. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  2257. mn->dseg_length = cpu_to_le32(len);
  2258. if (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM) {
  2259. memcpy(mgmt_b, ql84_mgmt->payload, len);
  2260. }
  2261. }
  2262. ret = qla2x00_issue_iocb(ha, mn, mn_dma, 0);
  2263. if ((ret != QLA_SUCCESS) || (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM)
  2264. || (ql84_mgmt->cmd == QLA84_MGMT_CHNG_CONFIG)) {
  2265. if (ret != QLA_SUCCESS)
  2266. DEBUG2(printk(KERN_ERR "%s(%lu): failed\n",
  2267. __func__, ha->host_no));
  2268. } else if ((ql84_mgmt->cmd == QLA84_MGMT_READ_MEM) ||
  2269. (ql84_mgmt->cmd == QLA84_MGMT_GET_INFO)) {
  2270. }
  2271. if (mgmt_b)
  2272. dma_free_coherent(&ha->hw->pdev->dev, len, mgmt_b, mgmt_dma);
  2273. exit_mgmt0:
  2274. dma_pool_free(ha->hw->s_dma_pool, mn, mn_dma);
  2275. return ret;
  2276. }