zfcp_fsf.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2010
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  19. {
  20. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  21. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  22. "fsrth_1", NULL);
  23. }
  24. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  25. unsigned long timeout)
  26. {
  27. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  28. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  29. fsf_req->timer.expires = jiffies + timeout;
  30. add_timer(&fsf_req->timer);
  31. }
  32. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  33. {
  34. BUG_ON(!fsf_req->erp_action);
  35. fsf_req->timer.function = zfcp_erp_timeout_handler;
  36. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  37. fsf_req->timer.expires = jiffies + 30 * HZ;
  38. add_timer(&fsf_req->timer);
  39. }
  40. /* association between FSF command and FSF QTCB type */
  41. static u32 fsf_qtcb_type[] = {
  42. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  43. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  52. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  53. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  54. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  55. };
  56. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  57. {
  58. u16 subtable = table >> 16;
  59. u16 rule = table & 0xffff;
  60. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  61. if (subtable && subtable < ARRAY_SIZE(act_type))
  62. dev_warn(&adapter->ccw_device->dev,
  63. "Access denied according to ACT rule type %s, "
  64. "rule %d\n", act_type[subtable], rule);
  65. }
  66. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  67. struct zfcp_port *port)
  68. {
  69. struct fsf_qtcb_header *header = &req->qtcb->header;
  70. dev_warn(&req->adapter->ccw_device->dev,
  71. "Access denied to port 0x%016Lx\n",
  72. (unsigned long long)port->wwpn);
  73. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  74. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  75. zfcp_erp_port_access_denied(port, "fspad_1", req);
  76. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  77. }
  78. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  79. struct zfcp_unit *unit)
  80. {
  81. struct fsf_qtcb_header *header = &req->qtcb->header;
  82. dev_warn(&req->adapter->ccw_device->dev,
  83. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  84. (unsigned long long)unit->fcp_lun,
  85. (unsigned long long)unit->port->wwpn);
  86. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  87. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  88. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  89. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  90. }
  91. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  92. {
  93. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  94. "operational because of an unsupported FC class\n");
  95. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  96. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  97. }
  98. /**
  99. * zfcp_fsf_req_free - free memory used by fsf request
  100. * @fsf_req: pointer to struct zfcp_fsf_req
  101. */
  102. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  103. {
  104. if (likely(req->pool)) {
  105. if (likely(req->qtcb))
  106. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  107. mempool_free(req, req->pool);
  108. return;
  109. }
  110. if (likely(req->qtcb))
  111. kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
  112. kfree(req);
  113. }
  114. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  115. {
  116. unsigned long flags;
  117. struct fsf_status_read_buffer *sr_buf = req->data;
  118. struct zfcp_adapter *adapter = req->adapter;
  119. struct zfcp_port *port;
  120. int d_id = ntoh24(sr_buf->d_id);
  121. read_lock_irqsave(&adapter->port_list_lock, flags);
  122. list_for_each_entry(port, &adapter->port_list, list)
  123. if (port->d_id == d_id) {
  124. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  125. break;
  126. }
  127. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  128. }
  129. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  130. struct fsf_link_down_info *link_down)
  131. {
  132. struct zfcp_adapter *adapter = req->adapter;
  133. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  134. return;
  135. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  136. zfcp_scsi_schedule_rports_block(adapter);
  137. if (!link_down)
  138. goto out;
  139. switch (link_down->error_code) {
  140. case FSF_PSQ_LINK_NO_LIGHT:
  141. dev_warn(&req->adapter->ccw_device->dev,
  142. "There is no light signal from the local "
  143. "fibre channel cable\n");
  144. break;
  145. case FSF_PSQ_LINK_WRAP_PLUG:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "There is a wrap plug instead of a fibre "
  148. "channel cable\n");
  149. break;
  150. case FSF_PSQ_LINK_NO_FCP:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The adjacent fibre channel node does not "
  153. "support FCP\n");
  154. break;
  155. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The FCP device is suspended because of a "
  158. "firmware update\n");
  159. break;
  160. case FSF_PSQ_LINK_INVALID_WWPN:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "The FCP device detected a WWPN that is "
  163. "duplicate or not valid\n");
  164. break;
  165. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "The fibre channel fabric does not support NPIV\n");
  168. break;
  169. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  170. dev_warn(&req->adapter->ccw_device->dev,
  171. "The FCP adapter cannot support more NPIV ports\n");
  172. break;
  173. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  174. dev_warn(&req->adapter->ccw_device->dev,
  175. "The adjacent switch cannot support "
  176. "more NPIV ports\n");
  177. break;
  178. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  179. dev_warn(&req->adapter->ccw_device->dev,
  180. "The FCP adapter could not log in to the "
  181. "fibre channel fabric\n");
  182. break;
  183. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  184. dev_warn(&req->adapter->ccw_device->dev,
  185. "The WWPN assignment file on the FCP adapter "
  186. "has been damaged\n");
  187. break;
  188. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  189. dev_warn(&req->adapter->ccw_device->dev,
  190. "The mode table on the FCP adapter "
  191. "has been damaged\n");
  192. break;
  193. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  194. dev_warn(&req->adapter->ccw_device->dev,
  195. "All NPIV ports on the FCP adapter have "
  196. "been assigned\n");
  197. break;
  198. default:
  199. dev_warn(&req->adapter->ccw_device->dev,
  200. "The link between the FCP adapter and "
  201. "the FC fabric is down\n");
  202. }
  203. out:
  204. zfcp_erp_adapter_failed(adapter, id, req);
  205. }
  206. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  207. {
  208. struct fsf_status_read_buffer *sr_buf = req->data;
  209. struct fsf_link_down_info *ldi =
  210. (struct fsf_link_down_info *) &sr_buf->payload;
  211. switch (sr_buf->status_subtype) {
  212. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  213. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  214. break;
  215. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  216. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  217. break;
  218. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  219. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  220. };
  221. }
  222. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  223. {
  224. struct zfcp_adapter *adapter = req->adapter;
  225. struct fsf_status_read_buffer *sr_buf = req->data;
  226. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  227. zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
  228. mempool_free(sr_buf, adapter->pool.status_read_data);
  229. zfcp_fsf_req_free(req);
  230. return;
  231. }
  232. zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
  233. switch (sr_buf->status_type) {
  234. case FSF_STATUS_READ_PORT_CLOSED:
  235. zfcp_fsf_status_read_port_closed(req);
  236. break;
  237. case FSF_STATUS_READ_INCOMING_ELS:
  238. zfcp_fc_incoming_els(req);
  239. break;
  240. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  241. break;
  242. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  243. dev_warn(&adapter->ccw_device->dev,
  244. "The error threshold for checksum statistics "
  245. "has been exceeded\n");
  246. zfcp_dbf_hba_berr(adapter->dbf, req);
  247. break;
  248. case FSF_STATUS_READ_LINK_DOWN:
  249. zfcp_fsf_status_read_link_down(req);
  250. break;
  251. case FSF_STATUS_READ_LINK_UP:
  252. dev_info(&adapter->ccw_device->dev,
  253. "The local link has been restored\n");
  254. /* All ports should be marked as ready to run again */
  255. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  256. ZFCP_STATUS_COMMON_RUNNING,
  257. ZFCP_SET);
  258. zfcp_erp_adapter_reopen(adapter,
  259. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  260. ZFCP_STATUS_COMMON_ERP_FAILED,
  261. "fssrh_2", req);
  262. break;
  263. case FSF_STATUS_READ_NOTIFICATION_LOST:
  264. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  265. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  266. req);
  267. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  268. queue_work(adapter->work_queue, &adapter->scan_work);
  269. break;
  270. case FSF_STATUS_READ_CFDC_UPDATED:
  271. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  272. break;
  273. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  274. adapter->adapter_features = sr_buf->payload.word[0];
  275. break;
  276. }
  277. mempool_free(sr_buf, adapter->pool.status_read_data);
  278. zfcp_fsf_req_free(req);
  279. atomic_inc(&adapter->stat_miss);
  280. queue_work(adapter->work_queue, &adapter->stat_work);
  281. }
  282. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  283. {
  284. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  285. case FSF_SQ_FCP_RSP_AVAILABLE:
  286. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  287. case FSF_SQ_NO_RETRY_POSSIBLE:
  288. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  289. return;
  290. case FSF_SQ_COMMAND_ABORTED:
  291. break;
  292. case FSF_SQ_NO_RECOM:
  293. dev_err(&req->adapter->ccw_device->dev,
  294. "The FCP adapter reported a problem "
  295. "that cannot be recovered\n");
  296. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  297. break;
  298. }
  299. /* all non-return stats set FSFREQ_ERROR*/
  300. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  301. }
  302. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  303. {
  304. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  305. return;
  306. switch (req->qtcb->header.fsf_status) {
  307. case FSF_UNKNOWN_COMMAND:
  308. dev_err(&req->adapter->ccw_device->dev,
  309. "The FCP adapter does not recognize the command 0x%x\n",
  310. req->qtcb->header.fsf_command);
  311. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  312. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  313. break;
  314. case FSF_ADAPTER_STATUS_AVAILABLE:
  315. zfcp_fsf_fsfstatus_qual_eval(req);
  316. break;
  317. }
  318. }
  319. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  320. {
  321. struct zfcp_adapter *adapter = req->adapter;
  322. struct fsf_qtcb *qtcb = req->qtcb;
  323. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  324. zfcp_dbf_hba_fsf_response(req);
  325. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  326. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  327. return;
  328. }
  329. switch (qtcb->prefix.prot_status) {
  330. case FSF_PROT_GOOD:
  331. case FSF_PROT_FSF_STATUS_PRESENTED:
  332. return;
  333. case FSF_PROT_QTCB_VERSION_ERROR:
  334. dev_err(&adapter->ccw_device->dev,
  335. "QTCB version 0x%x not supported by FCP adapter "
  336. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  337. psq->word[0], psq->word[1]);
  338. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  339. break;
  340. case FSF_PROT_ERROR_STATE:
  341. case FSF_PROT_SEQ_NUMB_ERROR:
  342. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  343. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  344. break;
  345. case FSF_PROT_UNSUPP_QTCB_TYPE:
  346. dev_err(&adapter->ccw_device->dev,
  347. "The QTCB type is not supported by the FCP adapter\n");
  348. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  349. break;
  350. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  351. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  352. &adapter->status);
  353. break;
  354. case FSF_PROT_DUPLICATE_REQUEST_ID:
  355. dev_err(&adapter->ccw_device->dev,
  356. "0x%Lx is an ambiguous request identifier\n",
  357. (unsigned long long)qtcb->bottom.support.req_handle);
  358. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  359. break;
  360. case FSF_PROT_LINK_DOWN:
  361. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  362. &psq->link_down_info);
  363. /* go through reopen to flush pending requests */
  364. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  365. break;
  366. case FSF_PROT_REEST_QUEUE:
  367. /* All ports should be marked as ready to run again */
  368. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  369. ZFCP_STATUS_COMMON_RUNNING,
  370. ZFCP_SET);
  371. zfcp_erp_adapter_reopen(adapter,
  372. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  373. ZFCP_STATUS_COMMON_ERP_FAILED,
  374. "fspse_8", req);
  375. break;
  376. default:
  377. dev_err(&adapter->ccw_device->dev,
  378. "0x%x is not a valid transfer protocol status\n",
  379. qtcb->prefix.prot_status);
  380. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  381. }
  382. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  383. }
  384. /**
  385. * zfcp_fsf_req_complete - process completion of a FSF request
  386. * @fsf_req: The FSF request that has been completed.
  387. *
  388. * When a request has been completed either from the FCP adapter,
  389. * or it has been dismissed due to a queue shutdown, this function
  390. * is called to process the completion status and trigger further
  391. * events related to the FSF request.
  392. */
  393. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  394. {
  395. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  396. zfcp_fsf_status_read_handler(req);
  397. return;
  398. }
  399. del_timer(&req->timer);
  400. zfcp_fsf_protstatus_eval(req);
  401. zfcp_fsf_fsfstatus_eval(req);
  402. req->handler(req);
  403. if (req->erp_action)
  404. zfcp_erp_notify(req->erp_action, 0);
  405. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  406. zfcp_fsf_req_free(req);
  407. else
  408. complete(&req->completion);
  409. }
  410. /**
  411. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  412. * @adapter: pointer to struct zfcp_adapter
  413. *
  414. * Never ever call this without shutting down the adapter first.
  415. * Otherwise the adapter would continue using and corrupting s390 storage.
  416. * Included BUG_ON() call to ensure this is done.
  417. * ERP is supposed to be the only user of this function.
  418. */
  419. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  420. {
  421. struct zfcp_fsf_req *req, *tmp;
  422. LIST_HEAD(remove_queue);
  423. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  424. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  425. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  426. list_del(&req->list);
  427. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  428. zfcp_fsf_req_complete(req);
  429. }
  430. }
  431. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  432. {
  433. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  434. struct zfcp_adapter *adapter = req->adapter;
  435. struct Scsi_Host *shost = adapter->scsi_host;
  436. struct fc_els_flogi *nsp, *plogi;
  437. /* adjust pointers for missing command code */
  438. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  439. - sizeof(u32));
  440. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  441. - sizeof(u32));
  442. if (req->data)
  443. memcpy(req->data, bottom, sizeof(*bottom));
  444. fc_host_port_name(shost) = nsp->fl_wwpn;
  445. fc_host_node_name(shost) = nsp->fl_wwnn;
  446. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  447. fc_host_speed(shost) = bottom->fc_link_speed;
  448. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  449. adapter->hydra_version = bottom->adapter_type;
  450. adapter->timer_ticks = bottom->timer_interval;
  451. adapter->stat_read_buf_num = max(bottom->status_read_buf_num, (u16)16);
  452. if (fc_host_permanent_port_name(shost) == -1)
  453. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  454. switch (bottom->fc_topology) {
  455. case FSF_TOPO_P2P:
  456. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  457. adapter->peer_wwpn = plogi->fl_wwpn;
  458. adapter->peer_wwnn = plogi->fl_wwnn;
  459. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  460. break;
  461. case FSF_TOPO_FABRIC:
  462. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  463. break;
  464. case FSF_TOPO_AL:
  465. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  466. /* fall through */
  467. default:
  468. dev_err(&adapter->ccw_device->dev,
  469. "Unknown or unsupported arbitrated loop "
  470. "fibre channel topology detected\n");
  471. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  472. return -EIO;
  473. }
  474. return 0;
  475. }
  476. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  477. {
  478. struct zfcp_adapter *adapter = req->adapter;
  479. struct fsf_qtcb *qtcb = req->qtcb;
  480. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  481. struct Scsi_Host *shost = adapter->scsi_host;
  482. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  483. return;
  484. adapter->fsf_lic_version = bottom->lic_version;
  485. adapter->adapter_features = bottom->adapter_features;
  486. adapter->connection_features = bottom->connection_features;
  487. adapter->peer_wwpn = 0;
  488. adapter->peer_wwnn = 0;
  489. adapter->peer_d_id = 0;
  490. switch (qtcb->header.fsf_status) {
  491. case FSF_GOOD:
  492. if (zfcp_fsf_exchange_config_evaluate(req))
  493. return;
  494. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  495. dev_err(&adapter->ccw_device->dev,
  496. "FCP adapter maximum QTCB size (%d bytes) "
  497. "is too small\n",
  498. bottom->max_qtcb_size);
  499. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  500. return;
  501. }
  502. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  503. &adapter->status);
  504. break;
  505. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  506. fc_host_node_name(shost) = 0;
  507. fc_host_port_name(shost) = 0;
  508. fc_host_port_id(shost) = 0;
  509. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  510. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  511. adapter->hydra_version = 0;
  512. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  513. &adapter->status);
  514. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  515. &qtcb->header.fsf_status_qual.link_down_info);
  516. break;
  517. default:
  518. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  519. return;
  520. }
  521. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  522. adapter->hardware_version = bottom->hardware_version;
  523. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  524. min(FC_SERIAL_NUMBER_SIZE, 17));
  525. EBCASC(fc_host_serial_number(shost),
  526. min(FC_SERIAL_NUMBER_SIZE, 17));
  527. }
  528. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  529. dev_err(&adapter->ccw_device->dev,
  530. "The FCP adapter only supports newer "
  531. "control block versions\n");
  532. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  533. return;
  534. }
  535. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  536. dev_err(&adapter->ccw_device->dev,
  537. "The FCP adapter only supports older "
  538. "control block versions\n");
  539. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  540. }
  541. }
  542. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  543. {
  544. struct zfcp_adapter *adapter = req->adapter;
  545. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  546. struct Scsi_Host *shost = adapter->scsi_host;
  547. if (req->data)
  548. memcpy(req->data, bottom, sizeof(*bottom));
  549. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  550. fc_host_permanent_port_name(shost) = bottom->wwpn;
  551. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  552. } else
  553. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  554. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  555. fc_host_supported_speeds(shost) = bottom->supported_speed;
  556. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  557. FC_FC4_LIST_SIZE);
  558. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  559. FC_FC4_LIST_SIZE);
  560. }
  561. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  562. {
  563. struct fsf_qtcb *qtcb = req->qtcb;
  564. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  565. return;
  566. switch (qtcb->header.fsf_status) {
  567. case FSF_GOOD:
  568. zfcp_fsf_exchange_port_evaluate(req);
  569. break;
  570. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  571. zfcp_fsf_exchange_port_evaluate(req);
  572. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  573. &qtcb->header.fsf_status_qual.link_down_info);
  574. break;
  575. }
  576. }
  577. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  578. {
  579. struct zfcp_fsf_req *req;
  580. if (likely(pool))
  581. req = mempool_alloc(pool, GFP_ATOMIC);
  582. else
  583. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  584. if (unlikely(!req))
  585. return NULL;
  586. memset(req, 0, sizeof(*req));
  587. req->pool = pool;
  588. return req;
  589. }
  590. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  591. {
  592. struct fsf_qtcb *qtcb;
  593. if (likely(pool))
  594. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  595. else
  596. qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
  597. if (unlikely(!qtcb))
  598. return NULL;
  599. memset(qtcb, 0, sizeof(*qtcb));
  600. return qtcb;
  601. }
  602. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  603. u32 fsf_cmd, u32 sbtype,
  604. mempool_t *pool)
  605. {
  606. struct zfcp_adapter *adapter = qdio->adapter;
  607. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  608. if (unlikely(!req))
  609. return ERR_PTR(-ENOMEM);
  610. if (adapter->req_no == 0)
  611. adapter->req_no++;
  612. INIT_LIST_HEAD(&req->list);
  613. init_timer(&req->timer);
  614. init_completion(&req->completion);
  615. req->adapter = adapter;
  616. req->fsf_command = fsf_cmd;
  617. req->req_id = adapter->req_no;
  618. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  619. if (likely(pool))
  620. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  621. else
  622. req->qtcb = zfcp_qtcb_alloc(NULL);
  623. if (unlikely(!req->qtcb)) {
  624. zfcp_fsf_req_free(req);
  625. return ERR_PTR(-ENOMEM);
  626. }
  627. req->seq_no = adapter->fsf_req_seq_no;
  628. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  629. req->qtcb->prefix.req_id = req->req_id;
  630. req->qtcb->prefix.ulp_info = 26;
  631. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  632. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  633. req->qtcb->header.req_handle = req->req_id;
  634. req->qtcb->header.fsf_command = req->fsf_command;
  635. }
  636. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  637. req->qtcb, sizeof(struct fsf_qtcb));
  638. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  639. zfcp_fsf_req_free(req);
  640. return ERR_PTR(-EIO);
  641. }
  642. return req;
  643. }
  644. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  645. {
  646. struct zfcp_adapter *adapter = req->adapter;
  647. struct zfcp_qdio *qdio = adapter->qdio;
  648. int with_qtcb = (req->qtcb != NULL);
  649. int req_id = req->req_id;
  650. zfcp_reqlist_add(adapter->req_list, req);
  651. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
  652. req->issued = get_clock();
  653. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  654. del_timer(&req->timer);
  655. /* lookup request again, list might have changed */
  656. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  657. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  658. return -EIO;
  659. }
  660. /* Don't increase for unsolicited status */
  661. if (with_qtcb)
  662. adapter->fsf_req_seq_no++;
  663. adapter->req_no++;
  664. return 0;
  665. }
  666. /**
  667. * zfcp_fsf_status_read - send status read request
  668. * @adapter: pointer to struct zfcp_adapter
  669. * @req_flags: request flags
  670. * Returns: 0 on success, ERROR otherwise
  671. */
  672. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  673. {
  674. struct zfcp_adapter *adapter = qdio->adapter;
  675. struct zfcp_fsf_req *req;
  676. struct fsf_status_read_buffer *sr_buf;
  677. int retval = -EIO;
  678. spin_lock_bh(&qdio->req_q_lock);
  679. if (zfcp_qdio_sbal_get(qdio))
  680. goto out;
  681. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
  682. adapter->pool.status_read_req);
  683. if (IS_ERR(req)) {
  684. retval = PTR_ERR(req);
  685. goto out;
  686. }
  687. sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
  688. if (!sr_buf) {
  689. retval = -ENOMEM;
  690. goto failed_buf;
  691. }
  692. memset(sr_buf, 0, sizeof(*sr_buf));
  693. req->data = sr_buf;
  694. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  695. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  696. retval = zfcp_fsf_req_send(req);
  697. if (retval)
  698. goto failed_req_send;
  699. goto out;
  700. failed_req_send:
  701. mempool_free(sr_buf, adapter->pool.status_read_data);
  702. failed_buf:
  703. zfcp_fsf_req_free(req);
  704. zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
  705. out:
  706. spin_unlock_bh(&qdio->req_q_lock);
  707. return retval;
  708. }
  709. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  710. {
  711. struct zfcp_unit *unit = req->data;
  712. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  713. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  714. return;
  715. switch (req->qtcb->header.fsf_status) {
  716. case FSF_PORT_HANDLE_NOT_VALID:
  717. if (fsq->word[0] == fsq->word[1]) {
  718. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  719. "fsafch1", req);
  720. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  721. }
  722. break;
  723. case FSF_LUN_HANDLE_NOT_VALID:
  724. if (fsq->word[0] == fsq->word[1]) {
  725. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  726. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  727. }
  728. break;
  729. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  730. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  731. break;
  732. case FSF_PORT_BOXED:
  733. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  734. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  735. break;
  736. case FSF_LUN_BOXED:
  737. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  738. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  739. break;
  740. case FSF_ADAPTER_STATUS_AVAILABLE:
  741. switch (fsq->word[0]) {
  742. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  743. zfcp_fc_test_link(unit->port);
  744. /* fall through */
  745. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  746. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  747. break;
  748. }
  749. break;
  750. case FSF_GOOD:
  751. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  752. break;
  753. }
  754. }
  755. /**
  756. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  757. * @old_req_id: unsigned long
  758. * @unit: pointer to struct zfcp_unit
  759. * Returns: pointer to struct zfcp_fsf_req
  760. */
  761. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  762. struct zfcp_unit *unit)
  763. {
  764. struct zfcp_fsf_req *req = NULL;
  765. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  766. spin_lock_bh(&qdio->req_q_lock);
  767. if (zfcp_qdio_sbal_get(qdio))
  768. goto out;
  769. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  770. SBAL_FLAGS0_TYPE_READ,
  771. qdio->adapter->pool.scsi_abort);
  772. if (IS_ERR(req)) {
  773. req = NULL;
  774. goto out;
  775. }
  776. if (unlikely(!(atomic_read(&unit->status) &
  777. ZFCP_STATUS_COMMON_UNBLOCKED)))
  778. goto out_error_free;
  779. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  780. req->data = unit;
  781. req->handler = zfcp_fsf_abort_fcp_command_handler;
  782. req->qtcb->header.lun_handle = unit->handle;
  783. req->qtcb->header.port_handle = unit->port->handle;
  784. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  785. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  786. if (!zfcp_fsf_req_send(req))
  787. goto out;
  788. out_error_free:
  789. zfcp_fsf_req_free(req);
  790. req = NULL;
  791. out:
  792. spin_unlock_bh(&qdio->req_q_lock);
  793. return req;
  794. }
  795. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  796. {
  797. struct zfcp_adapter *adapter = req->adapter;
  798. struct zfcp_fsf_ct_els *ct = req->data;
  799. struct fsf_qtcb_header *header = &req->qtcb->header;
  800. ct->status = -EINVAL;
  801. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  802. goto skip_fsfstatus;
  803. switch (header->fsf_status) {
  804. case FSF_GOOD:
  805. zfcp_dbf_san_ct_response(req);
  806. ct->status = 0;
  807. break;
  808. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  809. zfcp_fsf_class_not_supp(req);
  810. break;
  811. case FSF_ADAPTER_STATUS_AVAILABLE:
  812. switch (header->fsf_status_qual.word[0]){
  813. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  814. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  815. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  816. break;
  817. }
  818. break;
  819. case FSF_ACCESS_DENIED:
  820. break;
  821. case FSF_PORT_BOXED:
  822. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  823. break;
  824. case FSF_PORT_HANDLE_NOT_VALID:
  825. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  826. /* fall through */
  827. case FSF_GENERIC_COMMAND_REJECTED:
  828. case FSF_PAYLOAD_SIZE_MISMATCH:
  829. case FSF_REQUEST_SIZE_TOO_LARGE:
  830. case FSF_RESPONSE_SIZE_TOO_LARGE:
  831. case FSF_SBAL_MISMATCH:
  832. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  833. break;
  834. }
  835. skip_fsfstatus:
  836. if (ct->handler)
  837. ct->handler(ct->handler_data);
  838. }
  839. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  840. struct zfcp_qdio_req *q_req,
  841. struct scatterlist *sg_req,
  842. struct scatterlist *sg_resp)
  843. {
  844. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  845. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  846. zfcp_qdio_set_sbale_last(qdio, q_req);
  847. }
  848. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  849. struct scatterlist *sg_req,
  850. struct scatterlist *sg_resp,
  851. int max_sbals)
  852. {
  853. struct zfcp_adapter *adapter = req->adapter;
  854. u32 feat = adapter->adapter_features;
  855. int bytes;
  856. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  857. if (!zfcp_qdio_sg_one_sbale(sg_req) ||
  858. !zfcp_qdio_sg_one_sbale(sg_resp))
  859. return -EOPNOTSUPP;
  860. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  861. sg_req, sg_resp);
  862. return 0;
  863. }
  864. /* use single, unchained SBAL if it can hold the request */
  865. if (zfcp_qdio_sg_one_sbale(sg_req) || zfcp_qdio_sg_one_sbale(sg_resp)) {
  866. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  867. sg_req, sg_resp);
  868. return 0;
  869. }
  870. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  871. sg_req, max_sbals);
  872. if (bytes <= 0)
  873. return -EIO;
  874. req->qtcb->bottom.support.req_buf_length = bytes;
  875. zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
  876. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  877. sg_resp, max_sbals);
  878. req->qtcb->bottom.support.resp_buf_length = bytes;
  879. if (bytes <= 0)
  880. return -EIO;
  881. return 0;
  882. }
  883. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  884. struct scatterlist *sg_req,
  885. struct scatterlist *sg_resp,
  886. int max_sbals, unsigned int timeout)
  887. {
  888. int ret;
  889. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
  890. if (ret)
  891. return ret;
  892. /* common settings for ct/gs and els requests */
  893. if (timeout > 255)
  894. timeout = 255; /* max value accepted by hardware */
  895. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  896. req->qtcb->bottom.support.timeout = timeout;
  897. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  898. return 0;
  899. }
  900. /**
  901. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  902. * @ct: pointer to struct zfcp_send_ct with data for request
  903. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  904. */
  905. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  906. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  907. unsigned int timeout)
  908. {
  909. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  910. struct zfcp_fsf_req *req;
  911. int ret = -EIO;
  912. spin_lock_bh(&qdio->req_q_lock);
  913. if (zfcp_qdio_sbal_get(qdio))
  914. goto out;
  915. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  916. SBAL_FLAGS0_TYPE_WRITE_READ, pool);
  917. if (IS_ERR(req)) {
  918. ret = PTR_ERR(req);
  919. goto out;
  920. }
  921. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  922. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
  923. ZFCP_FSF_MAX_SBALS_PER_REQ, timeout);
  924. if (ret)
  925. goto failed_send;
  926. req->handler = zfcp_fsf_send_ct_handler;
  927. req->qtcb->header.port_handle = wka_port->handle;
  928. req->data = ct;
  929. zfcp_dbf_san_ct_request(req, wka_port->d_id);
  930. ret = zfcp_fsf_req_send(req);
  931. if (ret)
  932. goto failed_send;
  933. goto out;
  934. failed_send:
  935. zfcp_fsf_req_free(req);
  936. out:
  937. spin_unlock_bh(&qdio->req_q_lock);
  938. return ret;
  939. }
  940. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  941. {
  942. struct zfcp_fsf_ct_els *send_els = req->data;
  943. struct zfcp_port *port = send_els->port;
  944. struct fsf_qtcb_header *header = &req->qtcb->header;
  945. send_els->status = -EINVAL;
  946. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  947. goto skip_fsfstatus;
  948. switch (header->fsf_status) {
  949. case FSF_GOOD:
  950. zfcp_dbf_san_els_response(req);
  951. send_els->status = 0;
  952. break;
  953. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  954. zfcp_fsf_class_not_supp(req);
  955. break;
  956. case FSF_ADAPTER_STATUS_AVAILABLE:
  957. switch (header->fsf_status_qual.word[0]){
  958. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  959. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  960. case FSF_SQ_RETRY_IF_POSSIBLE:
  961. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  962. break;
  963. }
  964. break;
  965. case FSF_ELS_COMMAND_REJECTED:
  966. case FSF_PAYLOAD_SIZE_MISMATCH:
  967. case FSF_REQUEST_SIZE_TOO_LARGE:
  968. case FSF_RESPONSE_SIZE_TOO_LARGE:
  969. break;
  970. case FSF_ACCESS_DENIED:
  971. if (port)
  972. zfcp_fsf_access_denied_port(req, port);
  973. break;
  974. case FSF_SBAL_MISMATCH:
  975. /* should never occure, avoided in zfcp_fsf_send_els */
  976. /* fall through */
  977. default:
  978. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  979. break;
  980. }
  981. skip_fsfstatus:
  982. if (send_els->handler)
  983. send_els->handler(send_els->handler_data);
  984. }
  985. /**
  986. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  987. * @els: pointer to struct zfcp_send_els with data for the command
  988. */
  989. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  990. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  991. {
  992. struct zfcp_fsf_req *req;
  993. struct zfcp_qdio *qdio = adapter->qdio;
  994. int ret = -EIO;
  995. spin_lock_bh(&qdio->req_q_lock);
  996. if (zfcp_qdio_sbal_get(qdio))
  997. goto out;
  998. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  999. SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
  1000. if (IS_ERR(req)) {
  1001. ret = PTR_ERR(req);
  1002. goto out;
  1003. }
  1004. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1005. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
  1006. if (ret)
  1007. goto failed_send;
  1008. hton24(req->qtcb->bottom.support.d_id, d_id);
  1009. req->handler = zfcp_fsf_send_els_handler;
  1010. req->data = els;
  1011. zfcp_dbf_san_els_request(req);
  1012. ret = zfcp_fsf_req_send(req);
  1013. if (ret)
  1014. goto failed_send;
  1015. goto out;
  1016. failed_send:
  1017. zfcp_fsf_req_free(req);
  1018. out:
  1019. spin_unlock_bh(&qdio->req_q_lock);
  1020. return ret;
  1021. }
  1022. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1023. {
  1024. struct zfcp_fsf_req *req;
  1025. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1026. int retval = -EIO;
  1027. spin_lock_bh(&qdio->req_q_lock);
  1028. if (zfcp_qdio_sbal_get(qdio))
  1029. goto out;
  1030. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1031. SBAL_FLAGS0_TYPE_READ,
  1032. qdio->adapter->pool.erp_req);
  1033. if (IS_ERR(req)) {
  1034. retval = PTR_ERR(req);
  1035. goto out;
  1036. }
  1037. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1038. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1039. req->qtcb->bottom.config.feature_selection =
  1040. FSF_FEATURE_CFDC |
  1041. FSF_FEATURE_LUN_SHARING |
  1042. FSF_FEATURE_NOTIFICATION_LOST |
  1043. FSF_FEATURE_UPDATE_ALERT;
  1044. req->erp_action = erp_action;
  1045. req->handler = zfcp_fsf_exchange_config_data_handler;
  1046. erp_action->fsf_req_id = req->req_id;
  1047. zfcp_fsf_start_erp_timer(req);
  1048. retval = zfcp_fsf_req_send(req);
  1049. if (retval) {
  1050. zfcp_fsf_req_free(req);
  1051. erp_action->fsf_req_id = 0;
  1052. }
  1053. out:
  1054. spin_unlock_bh(&qdio->req_q_lock);
  1055. return retval;
  1056. }
  1057. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1058. struct fsf_qtcb_bottom_config *data)
  1059. {
  1060. struct zfcp_fsf_req *req = NULL;
  1061. int retval = -EIO;
  1062. spin_lock_bh(&qdio->req_q_lock);
  1063. if (zfcp_qdio_sbal_get(qdio))
  1064. goto out_unlock;
  1065. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1066. SBAL_FLAGS0_TYPE_READ, NULL);
  1067. if (IS_ERR(req)) {
  1068. retval = PTR_ERR(req);
  1069. goto out_unlock;
  1070. }
  1071. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1072. req->handler = zfcp_fsf_exchange_config_data_handler;
  1073. req->qtcb->bottom.config.feature_selection =
  1074. FSF_FEATURE_CFDC |
  1075. FSF_FEATURE_LUN_SHARING |
  1076. FSF_FEATURE_NOTIFICATION_LOST |
  1077. FSF_FEATURE_UPDATE_ALERT;
  1078. if (data)
  1079. req->data = data;
  1080. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1081. retval = zfcp_fsf_req_send(req);
  1082. spin_unlock_bh(&qdio->req_q_lock);
  1083. if (!retval)
  1084. wait_for_completion(&req->completion);
  1085. zfcp_fsf_req_free(req);
  1086. return retval;
  1087. out_unlock:
  1088. spin_unlock_bh(&qdio->req_q_lock);
  1089. return retval;
  1090. }
  1091. /**
  1092. * zfcp_fsf_exchange_port_data - request information about local port
  1093. * @erp_action: ERP action for the adapter for which port data is requested
  1094. * Returns: 0 on success, error otherwise
  1095. */
  1096. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1097. {
  1098. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1099. struct zfcp_fsf_req *req;
  1100. int retval = -EIO;
  1101. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1102. return -EOPNOTSUPP;
  1103. spin_lock_bh(&qdio->req_q_lock);
  1104. if (zfcp_qdio_sbal_get(qdio))
  1105. goto out;
  1106. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1107. SBAL_FLAGS0_TYPE_READ,
  1108. qdio->adapter->pool.erp_req);
  1109. if (IS_ERR(req)) {
  1110. retval = PTR_ERR(req);
  1111. goto out;
  1112. }
  1113. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1114. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1115. req->handler = zfcp_fsf_exchange_port_data_handler;
  1116. req->erp_action = erp_action;
  1117. erp_action->fsf_req_id = req->req_id;
  1118. zfcp_fsf_start_erp_timer(req);
  1119. retval = zfcp_fsf_req_send(req);
  1120. if (retval) {
  1121. zfcp_fsf_req_free(req);
  1122. erp_action->fsf_req_id = 0;
  1123. }
  1124. out:
  1125. spin_unlock_bh(&qdio->req_q_lock);
  1126. return retval;
  1127. }
  1128. /**
  1129. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1130. * @qdio: pointer to struct zfcp_qdio
  1131. * @data: pointer to struct fsf_qtcb_bottom_port
  1132. * Returns: 0 on success, error otherwise
  1133. */
  1134. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1135. struct fsf_qtcb_bottom_port *data)
  1136. {
  1137. struct zfcp_fsf_req *req = NULL;
  1138. int retval = -EIO;
  1139. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1140. return -EOPNOTSUPP;
  1141. spin_lock_bh(&qdio->req_q_lock);
  1142. if (zfcp_qdio_sbal_get(qdio))
  1143. goto out_unlock;
  1144. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1145. SBAL_FLAGS0_TYPE_READ, NULL);
  1146. if (IS_ERR(req)) {
  1147. retval = PTR_ERR(req);
  1148. goto out_unlock;
  1149. }
  1150. if (data)
  1151. req->data = data;
  1152. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1153. req->handler = zfcp_fsf_exchange_port_data_handler;
  1154. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1155. retval = zfcp_fsf_req_send(req);
  1156. spin_unlock_bh(&qdio->req_q_lock);
  1157. if (!retval)
  1158. wait_for_completion(&req->completion);
  1159. zfcp_fsf_req_free(req);
  1160. return retval;
  1161. out_unlock:
  1162. spin_unlock_bh(&qdio->req_q_lock);
  1163. return retval;
  1164. }
  1165. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1166. {
  1167. struct zfcp_port *port = req->data;
  1168. struct fsf_qtcb_header *header = &req->qtcb->header;
  1169. struct fc_els_flogi *plogi;
  1170. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1171. goto out;
  1172. switch (header->fsf_status) {
  1173. case FSF_PORT_ALREADY_OPEN:
  1174. break;
  1175. case FSF_ACCESS_DENIED:
  1176. zfcp_fsf_access_denied_port(req, port);
  1177. break;
  1178. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1179. dev_warn(&req->adapter->ccw_device->dev,
  1180. "Not enough FCP adapter resources to open "
  1181. "remote port 0x%016Lx\n",
  1182. (unsigned long long)port->wwpn);
  1183. zfcp_erp_port_failed(port, "fsoph_1", req);
  1184. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1185. break;
  1186. case FSF_ADAPTER_STATUS_AVAILABLE:
  1187. switch (header->fsf_status_qual.word[0]) {
  1188. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1189. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1190. case FSF_SQ_NO_RETRY_POSSIBLE:
  1191. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1192. break;
  1193. }
  1194. break;
  1195. case FSF_GOOD:
  1196. port->handle = header->port_handle;
  1197. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1198. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1199. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1200. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1201. &port->status);
  1202. /* check whether D_ID has changed during open */
  1203. /*
  1204. * FIXME: This check is not airtight, as the FCP channel does
  1205. * not monitor closures of target port connections caused on
  1206. * the remote side. Thus, they might miss out on invalidating
  1207. * locally cached WWPNs (and other N_Port parameters) of gone
  1208. * target ports. So, our heroic attempt to make things safe
  1209. * could be undermined by 'open port' response data tagged with
  1210. * obsolete WWPNs. Another reason to monitor potential
  1211. * connection closures ourself at least (by interpreting
  1212. * incoming ELS' and unsolicited status). It just crosses my
  1213. * mind that one should be able to cross-check by means of
  1214. * another GID_PN straight after a port has been opened.
  1215. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1216. */
  1217. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1218. if (req->qtcb->bottom.support.els1_length >=
  1219. FSF_PLOGI_MIN_LEN)
  1220. zfcp_fc_plogi_evaluate(port, plogi);
  1221. break;
  1222. case FSF_UNKNOWN_OP_SUBTYPE:
  1223. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1224. break;
  1225. }
  1226. out:
  1227. put_device(&port->dev);
  1228. }
  1229. /**
  1230. * zfcp_fsf_open_port - create and send open port request
  1231. * @erp_action: pointer to struct zfcp_erp_action
  1232. * Returns: 0 on success, error otherwise
  1233. */
  1234. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1235. {
  1236. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1237. struct zfcp_port *port = erp_action->port;
  1238. struct zfcp_fsf_req *req;
  1239. int retval = -EIO;
  1240. spin_lock_bh(&qdio->req_q_lock);
  1241. if (zfcp_qdio_sbal_get(qdio))
  1242. goto out;
  1243. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1244. SBAL_FLAGS0_TYPE_READ,
  1245. qdio->adapter->pool.erp_req);
  1246. if (IS_ERR(req)) {
  1247. retval = PTR_ERR(req);
  1248. goto out;
  1249. }
  1250. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1251. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1252. req->handler = zfcp_fsf_open_port_handler;
  1253. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1254. req->data = port;
  1255. req->erp_action = erp_action;
  1256. erp_action->fsf_req_id = req->req_id;
  1257. get_device(&port->dev);
  1258. zfcp_fsf_start_erp_timer(req);
  1259. retval = zfcp_fsf_req_send(req);
  1260. if (retval) {
  1261. zfcp_fsf_req_free(req);
  1262. erp_action->fsf_req_id = 0;
  1263. put_device(&port->dev);
  1264. }
  1265. out:
  1266. spin_unlock_bh(&qdio->req_q_lock);
  1267. return retval;
  1268. }
  1269. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1270. {
  1271. struct zfcp_port *port = req->data;
  1272. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1273. return;
  1274. switch (req->qtcb->header.fsf_status) {
  1275. case FSF_PORT_HANDLE_NOT_VALID:
  1276. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1277. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1278. break;
  1279. case FSF_ADAPTER_STATUS_AVAILABLE:
  1280. break;
  1281. case FSF_GOOD:
  1282. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1283. ZFCP_STATUS_COMMON_OPEN,
  1284. ZFCP_CLEAR);
  1285. break;
  1286. }
  1287. }
  1288. /**
  1289. * zfcp_fsf_close_port - create and send close port request
  1290. * @erp_action: pointer to struct zfcp_erp_action
  1291. * Returns: 0 on success, error otherwise
  1292. */
  1293. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1294. {
  1295. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1296. struct zfcp_fsf_req *req;
  1297. int retval = -EIO;
  1298. spin_lock_bh(&qdio->req_q_lock);
  1299. if (zfcp_qdio_sbal_get(qdio))
  1300. goto out;
  1301. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1302. SBAL_FLAGS0_TYPE_READ,
  1303. qdio->adapter->pool.erp_req);
  1304. if (IS_ERR(req)) {
  1305. retval = PTR_ERR(req);
  1306. goto out;
  1307. }
  1308. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1309. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1310. req->handler = zfcp_fsf_close_port_handler;
  1311. req->data = erp_action->port;
  1312. req->erp_action = erp_action;
  1313. req->qtcb->header.port_handle = erp_action->port->handle;
  1314. erp_action->fsf_req_id = req->req_id;
  1315. zfcp_fsf_start_erp_timer(req);
  1316. retval = zfcp_fsf_req_send(req);
  1317. if (retval) {
  1318. zfcp_fsf_req_free(req);
  1319. erp_action->fsf_req_id = 0;
  1320. }
  1321. out:
  1322. spin_unlock_bh(&qdio->req_q_lock);
  1323. return retval;
  1324. }
  1325. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1326. {
  1327. struct zfcp_fc_wka_port *wka_port = req->data;
  1328. struct fsf_qtcb_header *header = &req->qtcb->header;
  1329. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1330. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1331. goto out;
  1332. }
  1333. switch (header->fsf_status) {
  1334. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1335. dev_warn(&req->adapter->ccw_device->dev,
  1336. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1337. /* fall through */
  1338. case FSF_ADAPTER_STATUS_AVAILABLE:
  1339. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1340. /* fall through */
  1341. case FSF_ACCESS_DENIED:
  1342. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1343. break;
  1344. case FSF_GOOD:
  1345. wka_port->handle = header->port_handle;
  1346. /* fall through */
  1347. case FSF_PORT_ALREADY_OPEN:
  1348. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1349. }
  1350. out:
  1351. wake_up(&wka_port->completion_wq);
  1352. }
  1353. /**
  1354. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1355. * @wka_port: pointer to struct zfcp_fc_wka_port
  1356. * Returns: 0 on success, error otherwise
  1357. */
  1358. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1359. {
  1360. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1361. struct zfcp_fsf_req *req;
  1362. int retval = -EIO;
  1363. spin_lock_bh(&qdio->req_q_lock);
  1364. if (zfcp_qdio_sbal_get(qdio))
  1365. goto out;
  1366. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1367. SBAL_FLAGS0_TYPE_READ,
  1368. qdio->adapter->pool.erp_req);
  1369. if (unlikely(IS_ERR(req))) {
  1370. retval = PTR_ERR(req);
  1371. goto out;
  1372. }
  1373. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1374. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1375. req->handler = zfcp_fsf_open_wka_port_handler;
  1376. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1377. req->data = wka_port;
  1378. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1379. retval = zfcp_fsf_req_send(req);
  1380. if (retval)
  1381. zfcp_fsf_req_free(req);
  1382. out:
  1383. spin_unlock_bh(&qdio->req_q_lock);
  1384. return retval;
  1385. }
  1386. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1387. {
  1388. struct zfcp_fc_wka_port *wka_port = req->data;
  1389. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1390. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1391. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1392. }
  1393. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1394. wake_up(&wka_port->completion_wq);
  1395. }
  1396. /**
  1397. * zfcp_fsf_close_wka_port - create and send close wka port request
  1398. * @wka_port: WKA port to open
  1399. * Returns: 0 on success, error otherwise
  1400. */
  1401. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1402. {
  1403. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1404. struct zfcp_fsf_req *req;
  1405. int retval = -EIO;
  1406. spin_lock_bh(&qdio->req_q_lock);
  1407. if (zfcp_qdio_sbal_get(qdio))
  1408. goto out;
  1409. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1410. SBAL_FLAGS0_TYPE_READ,
  1411. qdio->adapter->pool.erp_req);
  1412. if (unlikely(IS_ERR(req))) {
  1413. retval = PTR_ERR(req);
  1414. goto out;
  1415. }
  1416. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1417. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1418. req->handler = zfcp_fsf_close_wka_port_handler;
  1419. req->data = wka_port;
  1420. req->qtcb->header.port_handle = wka_port->handle;
  1421. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1422. retval = zfcp_fsf_req_send(req);
  1423. if (retval)
  1424. zfcp_fsf_req_free(req);
  1425. out:
  1426. spin_unlock_bh(&qdio->req_q_lock);
  1427. return retval;
  1428. }
  1429. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1430. {
  1431. struct zfcp_port *port = req->data;
  1432. struct fsf_qtcb_header *header = &req->qtcb->header;
  1433. struct zfcp_unit *unit;
  1434. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1435. return;
  1436. switch (header->fsf_status) {
  1437. case FSF_PORT_HANDLE_NOT_VALID:
  1438. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1439. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1440. break;
  1441. case FSF_ACCESS_DENIED:
  1442. zfcp_fsf_access_denied_port(req, port);
  1443. break;
  1444. case FSF_PORT_BOXED:
  1445. /* can't use generic zfcp_erp_modify_port_status because
  1446. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1447. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1448. read_lock(&port->unit_list_lock);
  1449. list_for_each_entry(unit, &port->unit_list, list)
  1450. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1451. &unit->status);
  1452. read_unlock(&port->unit_list_lock);
  1453. zfcp_erp_port_boxed(port, "fscpph2", req);
  1454. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1455. break;
  1456. case FSF_ADAPTER_STATUS_AVAILABLE:
  1457. switch (header->fsf_status_qual.word[0]) {
  1458. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1459. /* fall through */
  1460. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1461. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1462. break;
  1463. }
  1464. break;
  1465. case FSF_GOOD:
  1466. /* can't use generic zfcp_erp_modify_port_status because
  1467. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1468. */
  1469. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1470. read_lock(&port->unit_list_lock);
  1471. list_for_each_entry(unit, &port->unit_list, list)
  1472. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1473. &unit->status);
  1474. read_unlock(&port->unit_list_lock);
  1475. break;
  1476. }
  1477. }
  1478. /**
  1479. * zfcp_fsf_close_physical_port - close physical port
  1480. * @erp_action: pointer to struct zfcp_erp_action
  1481. * Returns: 0 on success
  1482. */
  1483. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1484. {
  1485. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1486. struct zfcp_fsf_req *req;
  1487. int retval = -EIO;
  1488. spin_lock_bh(&qdio->req_q_lock);
  1489. if (zfcp_qdio_sbal_get(qdio))
  1490. goto out;
  1491. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1492. SBAL_FLAGS0_TYPE_READ,
  1493. qdio->adapter->pool.erp_req);
  1494. if (IS_ERR(req)) {
  1495. retval = PTR_ERR(req);
  1496. goto out;
  1497. }
  1498. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1499. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1500. req->data = erp_action->port;
  1501. req->qtcb->header.port_handle = erp_action->port->handle;
  1502. req->erp_action = erp_action;
  1503. req->handler = zfcp_fsf_close_physical_port_handler;
  1504. erp_action->fsf_req_id = req->req_id;
  1505. zfcp_fsf_start_erp_timer(req);
  1506. retval = zfcp_fsf_req_send(req);
  1507. if (retval) {
  1508. zfcp_fsf_req_free(req);
  1509. erp_action->fsf_req_id = 0;
  1510. }
  1511. out:
  1512. spin_unlock_bh(&qdio->req_q_lock);
  1513. return retval;
  1514. }
  1515. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1516. {
  1517. struct zfcp_adapter *adapter = req->adapter;
  1518. struct zfcp_unit *unit = req->data;
  1519. struct fsf_qtcb_header *header = &req->qtcb->header;
  1520. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1521. struct fsf_queue_designator *queue_designator =
  1522. &header->fsf_status_qual.fsf_queue_designator;
  1523. int exclusive, readwrite;
  1524. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1525. return;
  1526. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1527. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1528. ZFCP_STATUS_UNIT_SHARED |
  1529. ZFCP_STATUS_UNIT_READONLY,
  1530. &unit->status);
  1531. switch (header->fsf_status) {
  1532. case FSF_PORT_HANDLE_NOT_VALID:
  1533. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1534. /* fall through */
  1535. case FSF_LUN_ALREADY_OPEN:
  1536. break;
  1537. case FSF_ACCESS_DENIED:
  1538. zfcp_fsf_access_denied_unit(req, unit);
  1539. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1540. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1541. break;
  1542. case FSF_PORT_BOXED:
  1543. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1544. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1545. break;
  1546. case FSF_LUN_SHARING_VIOLATION:
  1547. if (header->fsf_status_qual.word[0])
  1548. dev_warn(&adapter->ccw_device->dev,
  1549. "LUN 0x%Lx on port 0x%Lx is already in "
  1550. "use by CSS%d, MIF Image ID %x\n",
  1551. (unsigned long long)unit->fcp_lun,
  1552. (unsigned long long)unit->port->wwpn,
  1553. queue_designator->cssid,
  1554. queue_designator->hla);
  1555. else
  1556. zfcp_act_eval_err(adapter,
  1557. header->fsf_status_qual.word[2]);
  1558. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1559. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1560. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1561. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1562. break;
  1563. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1564. dev_warn(&adapter->ccw_device->dev,
  1565. "No handle is available for LUN "
  1566. "0x%016Lx on port 0x%016Lx\n",
  1567. (unsigned long long)unit->fcp_lun,
  1568. (unsigned long long)unit->port->wwpn);
  1569. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1570. /* fall through */
  1571. case FSF_INVALID_COMMAND_OPTION:
  1572. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1573. break;
  1574. case FSF_ADAPTER_STATUS_AVAILABLE:
  1575. switch (header->fsf_status_qual.word[0]) {
  1576. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1577. zfcp_fc_test_link(unit->port);
  1578. /* fall through */
  1579. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1580. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1581. break;
  1582. }
  1583. break;
  1584. case FSF_GOOD:
  1585. unit->handle = header->lun_handle;
  1586. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1587. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1588. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1589. !zfcp_ccw_priv_sch(adapter)) {
  1590. exclusive = (bottom->lun_access_info &
  1591. FSF_UNIT_ACCESS_EXCLUSIVE);
  1592. readwrite = (bottom->lun_access_info &
  1593. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1594. if (!exclusive)
  1595. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1596. &unit->status);
  1597. if (!readwrite) {
  1598. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1599. &unit->status);
  1600. dev_info(&adapter->ccw_device->dev,
  1601. "SCSI device at LUN 0x%016Lx on port "
  1602. "0x%016Lx opened read-only\n",
  1603. (unsigned long long)unit->fcp_lun,
  1604. (unsigned long long)unit->port->wwpn);
  1605. }
  1606. if (exclusive && !readwrite) {
  1607. dev_err(&adapter->ccw_device->dev,
  1608. "Exclusive read-only access not "
  1609. "supported (unit 0x%016Lx, "
  1610. "port 0x%016Lx)\n",
  1611. (unsigned long long)unit->fcp_lun,
  1612. (unsigned long long)unit->port->wwpn);
  1613. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1614. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1615. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1616. } else if (!exclusive && readwrite) {
  1617. dev_err(&adapter->ccw_device->dev,
  1618. "Shared read-write access not "
  1619. "supported (unit 0x%016Lx, port "
  1620. "0x%016Lx)\n",
  1621. (unsigned long long)unit->fcp_lun,
  1622. (unsigned long long)unit->port->wwpn);
  1623. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1624. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1625. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1626. }
  1627. }
  1628. break;
  1629. }
  1630. }
  1631. /**
  1632. * zfcp_fsf_open_unit - open unit
  1633. * @erp_action: pointer to struct zfcp_erp_action
  1634. * Returns: 0 on success, error otherwise
  1635. */
  1636. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1637. {
  1638. struct zfcp_adapter *adapter = erp_action->adapter;
  1639. struct zfcp_qdio *qdio = adapter->qdio;
  1640. struct zfcp_fsf_req *req;
  1641. int retval = -EIO;
  1642. spin_lock_bh(&qdio->req_q_lock);
  1643. if (zfcp_qdio_sbal_get(qdio))
  1644. goto out;
  1645. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1646. SBAL_FLAGS0_TYPE_READ,
  1647. adapter->pool.erp_req);
  1648. if (IS_ERR(req)) {
  1649. retval = PTR_ERR(req);
  1650. goto out;
  1651. }
  1652. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1653. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1654. req->qtcb->header.port_handle = erp_action->port->handle;
  1655. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1656. req->handler = zfcp_fsf_open_unit_handler;
  1657. req->data = erp_action->unit;
  1658. req->erp_action = erp_action;
  1659. erp_action->fsf_req_id = req->req_id;
  1660. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1661. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1662. zfcp_fsf_start_erp_timer(req);
  1663. retval = zfcp_fsf_req_send(req);
  1664. if (retval) {
  1665. zfcp_fsf_req_free(req);
  1666. erp_action->fsf_req_id = 0;
  1667. }
  1668. out:
  1669. spin_unlock_bh(&qdio->req_q_lock);
  1670. return retval;
  1671. }
  1672. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1673. {
  1674. struct zfcp_unit *unit = req->data;
  1675. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1676. return;
  1677. switch (req->qtcb->header.fsf_status) {
  1678. case FSF_PORT_HANDLE_NOT_VALID:
  1679. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1680. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1681. break;
  1682. case FSF_LUN_HANDLE_NOT_VALID:
  1683. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1684. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1685. break;
  1686. case FSF_PORT_BOXED:
  1687. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1688. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1689. break;
  1690. case FSF_ADAPTER_STATUS_AVAILABLE:
  1691. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1692. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1693. zfcp_fc_test_link(unit->port);
  1694. /* fall through */
  1695. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1696. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1697. break;
  1698. }
  1699. break;
  1700. case FSF_GOOD:
  1701. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1702. break;
  1703. }
  1704. }
  1705. /**
  1706. * zfcp_fsf_close_unit - close zfcp unit
  1707. * @erp_action: pointer to struct zfcp_unit
  1708. * Returns: 0 on success, error otherwise
  1709. */
  1710. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1711. {
  1712. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1713. struct zfcp_fsf_req *req;
  1714. int retval = -EIO;
  1715. spin_lock_bh(&qdio->req_q_lock);
  1716. if (zfcp_qdio_sbal_get(qdio))
  1717. goto out;
  1718. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1719. SBAL_FLAGS0_TYPE_READ,
  1720. qdio->adapter->pool.erp_req);
  1721. if (IS_ERR(req)) {
  1722. retval = PTR_ERR(req);
  1723. goto out;
  1724. }
  1725. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1726. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1727. req->qtcb->header.port_handle = erp_action->port->handle;
  1728. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1729. req->handler = zfcp_fsf_close_unit_handler;
  1730. req->data = erp_action->unit;
  1731. req->erp_action = erp_action;
  1732. erp_action->fsf_req_id = req->req_id;
  1733. zfcp_fsf_start_erp_timer(req);
  1734. retval = zfcp_fsf_req_send(req);
  1735. if (retval) {
  1736. zfcp_fsf_req_free(req);
  1737. erp_action->fsf_req_id = 0;
  1738. }
  1739. out:
  1740. spin_unlock_bh(&qdio->req_q_lock);
  1741. return retval;
  1742. }
  1743. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1744. {
  1745. lat_rec->sum += lat;
  1746. lat_rec->min = min(lat_rec->min, lat);
  1747. lat_rec->max = max(lat_rec->max, lat);
  1748. }
  1749. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1750. {
  1751. struct fsf_qual_latency_info *lat_in;
  1752. struct latency_cont *lat = NULL;
  1753. struct zfcp_unit *unit = req->unit;
  1754. struct zfcp_blk_drv_data blktrc;
  1755. int ticks = req->adapter->timer_ticks;
  1756. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1757. blktrc.flags = 0;
  1758. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1759. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1760. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1761. blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
  1762. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1763. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1764. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1765. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1766. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1767. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1768. switch (req->qtcb->bottom.io.data_direction) {
  1769. case FSF_DATADIR_READ:
  1770. lat = &unit->latencies.read;
  1771. break;
  1772. case FSF_DATADIR_WRITE:
  1773. lat = &unit->latencies.write;
  1774. break;
  1775. case FSF_DATADIR_CMND:
  1776. lat = &unit->latencies.cmd;
  1777. break;
  1778. }
  1779. if (lat) {
  1780. spin_lock(&unit->latencies.lock);
  1781. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1782. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1783. lat->counter++;
  1784. spin_unlock(&unit->latencies.lock);
  1785. }
  1786. }
  1787. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1788. sizeof(blktrc));
  1789. }
  1790. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1791. {
  1792. struct scsi_cmnd *scpnt;
  1793. struct fcp_resp_with_ext *fcp_rsp;
  1794. unsigned long flags;
  1795. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1796. scpnt = req->data;
  1797. if (unlikely(!scpnt)) {
  1798. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1799. return;
  1800. }
  1801. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1802. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1803. goto skip_fsfstatus;
  1804. }
  1805. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1806. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1807. skip_fsfstatus:
  1808. zfcp_fsf_req_trace(req, scpnt);
  1809. zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
  1810. scpnt->host_scribble = NULL;
  1811. (scpnt->scsi_done) (scpnt);
  1812. /*
  1813. * We must hold this lock until scsi_done has been called.
  1814. * Otherwise we may call scsi_done after abort regarding this
  1815. * command has completed.
  1816. * Note: scsi_done must not block!
  1817. */
  1818. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1819. }
  1820. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1821. {
  1822. struct fcp_resp_with_ext *fcp_rsp;
  1823. struct fcp_resp_rsp_info *rsp_info;
  1824. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1825. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1826. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1827. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1828. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1829. }
  1830. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1831. {
  1832. struct zfcp_unit *unit;
  1833. struct fsf_qtcb_header *header = &req->qtcb->header;
  1834. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1835. unit = req->data;
  1836. else
  1837. unit = req->unit;
  1838. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1839. goto skip_fsfstatus;
  1840. switch (header->fsf_status) {
  1841. case FSF_HANDLE_MISMATCH:
  1842. case FSF_PORT_HANDLE_NOT_VALID:
  1843. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1844. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1845. break;
  1846. case FSF_FCPLUN_NOT_VALID:
  1847. case FSF_LUN_HANDLE_NOT_VALID:
  1848. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1849. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1850. break;
  1851. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1852. zfcp_fsf_class_not_supp(req);
  1853. break;
  1854. case FSF_ACCESS_DENIED:
  1855. zfcp_fsf_access_denied_unit(req, unit);
  1856. break;
  1857. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1858. dev_err(&req->adapter->ccw_device->dev,
  1859. "Incorrect direction %d, unit 0x%016Lx on port "
  1860. "0x%016Lx closed\n",
  1861. req->qtcb->bottom.io.data_direction,
  1862. (unsigned long long)unit->fcp_lun,
  1863. (unsigned long long)unit->port->wwpn);
  1864. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1865. req);
  1866. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1867. break;
  1868. case FSF_CMND_LENGTH_NOT_VALID:
  1869. dev_err(&req->adapter->ccw_device->dev,
  1870. "Incorrect CDB length %d, unit 0x%016Lx on "
  1871. "port 0x%016Lx closed\n",
  1872. req->qtcb->bottom.io.fcp_cmnd_length,
  1873. (unsigned long long)unit->fcp_lun,
  1874. (unsigned long long)unit->port->wwpn);
  1875. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1876. req);
  1877. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1878. break;
  1879. case FSF_PORT_BOXED:
  1880. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1881. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1882. break;
  1883. case FSF_LUN_BOXED:
  1884. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1885. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1886. break;
  1887. case FSF_ADAPTER_STATUS_AVAILABLE:
  1888. if (header->fsf_status_qual.word[0] ==
  1889. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1890. zfcp_fc_test_link(unit->port);
  1891. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1892. break;
  1893. }
  1894. skip_fsfstatus:
  1895. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1896. zfcp_fsf_send_fcp_ctm_handler(req);
  1897. else {
  1898. zfcp_fsf_send_fcp_command_task_handler(req);
  1899. req->unit = NULL;
  1900. put_device(&unit->dev);
  1901. }
  1902. }
  1903. /**
  1904. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1905. * @unit: unit where command is sent to
  1906. * @scsi_cmnd: scsi command to be sent
  1907. */
  1908. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  1909. struct scsi_cmnd *scsi_cmnd)
  1910. {
  1911. struct zfcp_fsf_req *req;
  1912. struct fcp_cmnd *fcp_cmnd;
  1913. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  1914. int real_bytes, retval = -EIO;
  1915. struct zfcp_adapter *adapter = unit->port->adapter;
  1916. struct zfcp_qdio *qdio = adapter->qdio;
  1917. if (unlikely(!(atomic_read(&unit->status) &
  1918. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1919. return -EBUSY;
  1920. spin_lock(&qdio->req_q_lock);
  1921. if (atomic_read(&qdio->req_q.count) <= 0) {
  1922. atomic_inc(&qdio->req_q_full);
  1923. goto out;
  1924. }
  1925. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1926. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  1927. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1928. sbtype, adapter->pool.scsi_req);
  1929. if (IS_ERR(req)) {
  1930. retval = PTR_ERR(req);
  1931. goto out;
  1932. }
  1933. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1934. req->unit = unit;
  1935. req->data = scsi_cmnd;
  1936. req->handler = zfcp_fsf_send_fcp_command_handler;
  1937. req->qtcb->header.lun_handle = unit->handle;
  1938. req->qtcb->header.port_handle = unit->port->handle;
  1939. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  1940. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  1941. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1942. /*
  1943. * set depending on data direction:
  1944. * data direction bits in SBALE (SB Type)
  1945. * data direction bits in QTCB
  1946. */
  1947. switch (scsi_cmnd->sc_data_direction) {
  1948. case DMA_NONE:
  1949. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  1950. break;
  1951. case DMA_FROM_DEVICE:
  1952. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  1953. break;
  1954. case DMA_TO_DEVICE:
  1955. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  1956. break;
  1957. case DMA_BIDIRECTIONAL:
  1958. goto failed_scsi_cmnd;
  1959. }
  1960. get_device(&unit->dev);
  1961. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1962. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
  1963. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1964. scsi_sglist(scsi_cmnd),
  1965. ZFCP_FSF_MAX_SBALS_PER_REQ);
  1966. if (unlikely(real_bytes < 0)) {
  1967. if (req->qdio_req.sbal_number >= ZFCP_FSF_MAX_SBALS_PER_REQ) {
  1968. dev_err(&adapter->ccw_device->dev,
  1969. "Oversize data package, unit 0x%016Lx "
  1970. "on port 0x%016Lx closed\n",
  1971. (unsigned long long)unit->fcp_lun,
  1972. (unsigned long long)unit->port->wwpn);
  1973. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  1974. retval = -EINVAL;
  1975. }
  1976. goto failed_scsi_cmnd;
  1977. }
  1978. retval = zfcp_fsf_req_send(req);
  1979. if (unlikely(retval))
  1980. goto failed_scsi_cmnd;
  1981. goto out;
  1982. failed_scsi_cmnd:
  1983. put_device(&unit->dev);
  1984. zfcp_fsf_req_free(req);
  1985. scsi_cmnd->host_scribble = NULL;
  1986. out:
  1987. spin_unlock(&qdio->req_q_lock);
  1988. return retval;
  1989. }
  1990. /**
  1991. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  1992. * @unit: pointer to struct zfcp_unit
  1993. * @tm_flags: unsigned byte for task management flags
  1994. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1995. */
  1996. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  1997. {
  1998. struct zfcp_fsf_req *req = NULL;
  1999. struct fcp_cmnd *fcp_cmnd;
  2000. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  2001. if (unlikely(!(atomic_read(&unit->status) &
  2002. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2003. return NULL;
  2004. spin_lock_bh(&qdio->req_q_lock);
  2005. if (zfcp_qdio_sbal_get(qdio))
  2006. goto out;
  2007. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2008. SBAL_FLAGS0_TYPE_WRITE,
  2009. qdio->adapter->pool.scsi_req);
  2010. if (IS_ERR(req)) {
  2011. req = NULL;
  2012. goto out;
  2013. }
  2014. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2015. req->data = unit;
  2016. req->handler = zfcp_fsf_send_fcp_command_handler;
  2017. req->qtcb->header.lun_handle = unit->handle;
  2018. req->qtcb->header.port_handle = unit->port->handle;
  2019. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2020. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2021. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2022. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2023. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2024. zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
  2025. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2026. if (!zfcp_fsf_req_send(req))
  2027. goto out;
  2028. zfcp_fsf_req_free(req);
  2029. req = NULL;
  2030. out:
  2031. spin_unlock_bh(&qdio->req_q_lock);
  2032. return req;
  2033. }
  2034. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2035. {
  2036. }
  2037. /**
  2038. * zfcp_fsf_control_file - control file upload/download
  2039. * @adapter: pointer to struct zfcp_adapter
  2040. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2041. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2042. */
  2043. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2044. struct zfcp_fsf_cfdc *fsf_cfdc)
  2045. {
  2046. struct zfcp_qdio *qdio = adapter->qdio;
  2047. struct zfcp_fsf_req *req = NULL;
  2048. struct fsf_qtcb_bottom_support *bottom;
  2049. int direction, retval = -EIO, bytes;
  2050. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2051. return ERR_PTR(-EOPNOTSUPP);
  2052. switch (fsf_cfdc->command) {
  2053. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2054. direction = SBAL_FLAGS0_TYPE_WRITE;
  2055. break;
  2056. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2057. direction = SBAL_FLAGS0_TYPE_READ;
  2058. break;
  2059. default:
  2060. return ERR_PTR(-EINVAL);
  2061. }
  2062. spin_lock_bh(&qdio->req_q_lock);
  2063. if (zfcp_qdio_sbal_get(qdio))
  2064. goto out;
  2065. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
  2066. if (IS_ERR(req)) {
  2067. retval = -EPERM;
  2068. goto out;
  2069. }
  2070. req->handler = zfcp_fsf_control_file_handler;
  2071. bottom = &req->qtcb->bottom.support;
  2072. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2073. bottom->option = fsf_cfdc->option;
  2074. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  2075. fsf_cfdc->sg,
  2076. ZFCP_FSF_MAX_SBALS_PER_REQ);
  2077. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2078. zfcp_fsf_req_free(req);
  2079. goto out;
  2080. }
  2081. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2082. retval = zfcp_fsf_req_send(req);
  2083. out:
  2084. spin_unlock_bh(&qdio->req_q_lock);
  2085. if (!retval) {
  2086. wait_for_completion(&req->completion);
  2087. return req;
  2088. }
  2089. return ERR_PTR(retval);
  2090. }
  2091. /**
  2092. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2093. * @adapter: pointer to struct zfcp_adapter
  2094. * @sbal_idx: response queue index of SBAL to be processed
  2095. */
  2096. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2097. {
  2098. struct zfcp_adapter *adapter = qdio->adapter;
  2099. struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
  2100. struct qdio_buffer_element *sbale;
  2101. struct zfcp_fsf_req *fsf_req;
  2102. unsigned long req_id;
  2103. int idx;
  2104. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2105. sbale = &sbal->element[idx];
  2106. req_id = (unsigned long) sbale->addr;
  2107. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2108. if (!fsf_req)
  2109. /*
  2110. * Unknown request means that we have potentially memory
  2111. * corruption and must stop the machine immediately.
  2112. */
  2113. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2114. req_id, dev_name(&adapter->ccw_device->dev));
  2115. fsf_req->qdio_req.sbal_response = sbal_idx;
  2116. fsf_req->qdio_req.qdio_inb_usage =
  2117. atomic_read(&qdio->resp_q.count);
  2118. zfcp_fsf_req_complete(fsf_req);
  2119. if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
  2120. break;
  2121. }
  2122. }